Skip to content

Conversation

@spoike
Copy link
Member

@spoike spoike commented Nov 18, 2015

Adds createReducer function for creating a data store that uses pure functions to alter it's state. Much like the reduce function in lodash/underscore.

Usage:

var addUser = Reflux.createAction({ sync: true });
var reducer = Reflux.createReducer({ users: [] });

reducer.on(addUser, function(data, newUser) {
  data.users.push(newUser);
  return data;
})

addUser("John Doe");
reducer.peek(); // outputs { users: ["John Doe"] }

Todo:

  • Either implement getInitialState or let react mixins look at the peek function instead.
  • Should I add an unsubscribe function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants