This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function for validating actions; bug fixes
- Loading branch information
Showing
14 changed files
with
174 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": ["syntax-async-functions", "transform-regenerator"] | ||
"plugins": ["syntax-async-functions", "transform-regenerator", "transform-object-rest-spread"] | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
node_modules | ||
lib | ||
coverage |
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,4 @@ | ||
instrumentation: | ||
root: src | ||
extensions: | ||
- .js |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
src | ||
test | ||
node_modules |
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
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 |
---|---|---|
@@ -1,15 +1,26 @@ | ||
import { createStore, applyMiddleware, compose } from 'redux' | ||
import { createStore, applyMiddleware, compose, combineReducers } from 'redux' | ||
|
||
const createReduxState = (reducer, additionalMiddleware) => (initialState, saveAction) => { | ||
const saveActionMiddleware = () => { | ||
function createReduxStore({ reducer, additionalEnhancer, initialState, saveAction, clientId, isActionValid }) { | ||
function reducerWithClientId(state, action) { | ||
return {...reducer(state, action), clientId}; | ||
} | ||
|
||
const saveActionMiddleware = applyMiddleware((store) => { | ||
return (next) => (action) => { | ||
const state = store.getState(); | ||
const validAction = action._originatedFromServer || isActionValid(state, action, clientId); | ||
if (!validAction) { | ||
console.warn('Rejecting action %j as it is not valid for the current state: %j', action, state); | ||
return; | ||
} | ||
const nextAction = next(action); | ||
saveAction(nextAction); | ||
return nextAction; | ||
} | ||
}; | ||
const middleware = additionalMiddleware ? compose(additionalMiddleware, saveActionMiddleware) : saveActionMiddleware; | ||
return createStore(reducer, initialState, applyMiddleware(middleware)); | ||
}; | ||
}); | ||
|
||
const enhancer = additionalEnhancer ? compose(additionalEnhancer, saveActionMiddleware) : saveActionMiddleware; | ||
return createStore(reducerWithClientId, initialState, enhancer); | ||
} | ||
|
||
export default createReduxState; | ||
export default createReduxStore; |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import createSaveActionFunction from './save-action' | ||
|
||
function initializeServer(db, client, mergeActions) { | ||
const saveAction = createSaveActionFunction(db, mergeActions); | ||
function initializeServer({ db, client, mergeActions, reducer, isActionValid }) { | ||
const saveAction = createSaveActionFunction({ db, mergeActions, reducer, isActionValid }); | ||
db.onNewAction(client.emitAction.bind(client)); | ||
client.onSaveActionRequest(saveAction); | ||
return saveAction; | ||
} | ||
|
||
export default initializeServer; |
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
Oops, something went wrong.