Skip to content

Instantly share code, notes, and snippets.

@chris-ramon
Created June 2, 2015 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-ramon/934b7c348267700c1991 to your computer and use it in GitHub Desktop.
Save chris-ramon/934b7c348267700c1991 to your computer and use it in GitHub Desktop.
flux notes - simple flux implementation.
// simple flux implementation based on facebook/react examples
// 1. Component
class App extends Component {
foo() {
yStoreActions.create(payload);
}
componentDidMount() {
yStore.on(CHANGE_EVENT, this._onChange);
}
componentWillUnmount() {
yStore.removeListener(CHANGE_EVENT, this._onChange);
}
_onChange() {
this.setState();
}
}
// 2. Actions
var actions = {
create: function(payload) {
AppDispatcher.dispatch({
actionType: EntityConstants.CREATE,
payload: payload
});
}
};
// 3. Store
class YStore extends EventEmitter {
emitChange() {
this.emit(CHANGE_EVENT);
}
}
AppDispatcher.register(function(action) {
swithc(action.actionType) {
case EntityConstats.CREATE:
YStore.emitChange();
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment