fluxxor icon indicating copy to clipboard operation
fluxxor copied to clipboard

collection store sugar

Open brigand opened this issue 10 years ago • 0 comments

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");
  },
});

brigand avatar Jun 12 '14 05:06 brigand