Created
December 8, 2017 12:50
-
-
Save vzaidman/6c1361e452b603e2b366fa06d9ddc7ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
makeAsyncActionCreator as makeAsyncActionCreatorOrig, | |
makeActionCreator as makeActionCreatorOrig, | |
composeReducers, | |
makeAsyncReducer, | |
makeReducer, | |
} from 'redux-toolbelt' | |
const makeAsyncActionCreator = makeAsyncActionCreatorOrig.withDefaults({ prefix: 'document/' }) | |
const makeActionCreator = makeActionCreatorOrig.withDefaults({ prefix: 'document/' }) | |
export const addPage = makeActionCreator('addPage') | |
export const clonePage = makeActionCreator('clonePage') | |
export const splitPage = makeActionCreator('splitPage') | |
export const movePage = makeActionCreator('movePage') | |
export const removePage = makeActionCreator('removePage') | |
// ... many more actions here | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const permissions = makeReducer(/* ... */) | |
const animations = composeReducers(/* ... */) | |
const sounds = composeReducers(/* ... */) | |
const metadata = makeAsyncReducer(/* ... */) | |
const pages = composeReducers(/* ... */) | |
const activePageIndex = makeReducer(/* ... */) | |
//... more intermediate reducers here | |
export const document = composeReducers( | |
{ | |
permissions, | |
metadata, | |
content: { | |
pages: composeReducers({ | |
pages, | |
activePageIndex, | |
}), | |
animations, | |
sounds, | |
}, | |
viewState: composeReducers({ | |
lastPageId: makeReducer( | |
[addPage, clonePage, splitPage], | |
(state, { payload: page }) => page.id) | |
), | |
/* ... more ... */ | |
}), | |
}, | |
createReducer(removePage, (state, { payload: id }) => { | |
if(id !== state.viewState.lastPageId){ | |
return state | |
} | |
return dotProp.set(state, 'viewState.lastPageId', state.content.pages[0].id) | |
}) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment