Skip to content

collection store sugar #31

Open
Open
@brigand

Description

@brigand

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions