Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection store sugar #31

Open
brigand opened this issue Jun 12, 2014 · 0 comments
Open

collection store sugar #31

brigand opened this issue Jun 12, 2014 · 0 comments

Comments

@brigand
Copy link

brigand commented Jun 12, 2014

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");
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant