| 12345678910111213141516171819202122232425262728 |
- import { _ } from '../../utils'
- import { handleActions } from 'redux-actions'
- import { combineReducers } from 'redux'
- import {
- ADD_NOTE, UPDATE_NOTE, UPDATE_SELECTED_NOTE,
- REMOVE_NOTE, SELECT_NOTE, UNSELECT_NOTE
- } from '../Actions'
-
- const MOCK_NOTES = [
- {id: _.uniqueId(), title: 'First note', content: 'This is a little note' },
- {id: _.uniqueId(), title: 'Second note', content: '### This is a little md note' },
- ]
-
- const selectedNote = handleActions({
- [SELECT_NOTE]: (state, action) => state = action.payload,
- [UPDATE_SELECTED_NOTE]: (state, action) => ({...state, ...action.payload }),
- [UNSELECT_NOTE]: (state, action) => null
- }, null)
-
- const notes = handleActions({
- [ADD_NOTE]: (state, action) => [...state, { id: _.uniqueId(), title: 'new_note', content: '' }],
- [UPDATE_NOTE]: (state, action) => _.updateWhere(state, action.payload, _.idCheck(action.payload.id)),
- [REMOVE_NOTE]: (state, action) => _.reject(state, _.idCheck(action.payload.id)),
- }, MOCK_NOTES)
-
- const note = combineReducers({ notes, selectedNote })
-
- export default note
|