fluxxor
fluxxor copied to clipboard
collection store sugar
Some sugar for simple stores. It implements handleAdd
, handleRemove
, handleEmpty
, getState
, emptyWhere
, setCollectionName
.
var TodoStore = Fluxxor.createCollectionStore({
actions: {
"ADD_TODO": "handleAdd",
"TOGGLE_TODO": "handleToggleTodo",
"CLEAR_TODOS": "handleClear"
},
initialize: function() {
// provide the property name to fluxxor
this.setCollectionName("todos");
},
handleToggleTodo: function(payload) {
payload.todo.complete = !payload.todo.complete;
this.emit("change");
},
handleClear: function() {
this.removeWhere(function(todo){
return todo.complete;
});
this.emit("change");
},
});