Skip to content

Instantly share code, notes, and snippets.

@jondot
Created October 29, 2015 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jondot/7234bb811d9c83680600 to your computer and use it in GitHub Desktop.
Save jondot/7234bb811d9c83680600 to your computer and use it in GitHub Desktop.
A ReducerStore
class ReducerStore {
static handler(store=new Store, action){
var fn = store[action.type]
if(fn){
return fn(action)
} else {
return store
}
}
constructor(items=Immutable.List()){
this.items = items
}
list(){
return this.items.toArray()
}
find(id){
return this.items.find(this._byId(id))
}
load(action){
var list = action.payload.items
return new Store(
Store.sort(
Immutable.List( _.map(list, (raw)=>{
return Item.fromJSON(raw)
}))
)
)
}
...
}
module.exports = applyMiddleware(oplog)(createStore)(ReducerStore.handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment