Created
December 23, 2014 01:34
-
-
Save garbles/51ad75e16542f852e150 to your computer and use it in GitHub Desktop.
Base Store class with ES6 and CommonJS for Flux
This file contains hidden or 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
let EventEmitter = require('events').EventEmitter; | |
const CHANGE_EVENT = 'CHANGE_EVENT'; | |
class BaseStore extends EventEmitter { | |
emitChange () { | |
this.emit(CHANGE_EVENT); | |
} | |
addChangeListener (callback) { | |
this.on(CHANGE_EVENT, callback); | |
} | |
removeChangeListener (callback) { | |
this.removeListener(CHANGE_EVENT, callback); | |
} | |
} | |
module.exports = BaseStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can write
import EventEmitter from 'eventemitter3'
andexport default class BaseStore
instead of module.exports :)