Skip to content

Instantly share code, notes, and snippets.

@hwclass
Last active June 4, 2016 22:34
Show Gist options
  • Save hwclass/9bbc4dc305f6fee3900ee36f41047eb6 to your computer and use it in GitHub Desktop.
Save hwclass/9bbc4dc305f6fee3900ee36f41047eb6 to your computer and use it in GitHub Desktop.
class DummyEventEmitter {
//it is added to make the publishing feel like an emit
//event in EventEmitter library.
emit(eventName, callback) {
alert(eventName, callback);
}
}
class CounterStore extends DummyEventEmitter {
constructor(state) {
super();
this.state = state;
}
handleChange(EVENT_NAME, updatedStore) {
publish(EVENT_NAME, updatedStore);
}
increment() {
this.state.counter++;
this.publish('INCREMENT', this.state);
}
decrement() {
this.state.counter--;
this.publish('DECREMENT', this.state);
}
publish(eventName, updatedStore) {
this.emit(eventName, updatedStore);
}
};
let counterStore = new CounterStore({
counter: 0
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment