Created
October 29, 2015 19:10
-
-
Save jondot/7234bb811d9c83680600 to your computer and use it in GitHub Desktop.
A ReducerStore
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
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