Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relay new actions and current state instead of the whole liftedState …
…with history tree Related to #23.
- Loading branch information
1 parent
ddffd82
commit 3ab3724
Showing
4 changed files
with
85 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import parseJSON from '../utils/parseJSON'; | ||
|
||
function recompute(previousLiftedState, storeState, action) { | ||
let liftedState = { ...previousLiftedState }; | ||
liftedState.stagedActionIds.push(liftedState.nextActionId); | ||
liftedState.actionsById[liftedState.nextActionId] = action; | ||
liftedState.nextActionId++; | ||
liftedState.computedStates.push({ state: storeState }); | ||
liftedState.currentStateIndex++; | ||
return liftedState; | ||
} | ||
|
||
export default function updateState(store, request) { | ||
const payload = parseJSON(request.payload); | ||
if (!payload) return null; | ||
|
||
if (request.type === 'ACTION') { | ||
store.liftedStore.setState( | ||
recompute(store.liftedStore.getState(), payload, request.action) | ||
); | ||
} else if (request.type === 'STATE') { | ||
store.liftedStore.setState(payload); | ||
} | ||
|
||
return payload; | ||
} |