Last active
June 4, 2016 22:34
-
-
Save hwclass/9bbc4dc305f6fee3900ee36f41047eb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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