Skip to content

Instantly share code, notes, and snippets.

@garbles
Created December 23, 2014 01:34
Show Gist options
  • Save garbles/51ad75e16542f852e150 to your computer and use it in GitHub Desktop.
Save garbles/51ad75e16542f852e150 to your computer and use it in GitHub Desktop.
Base Store class with ES6 and CommonJS for Flux
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;
@ruslansavenok
Copy link

You can write
import EventEmitter from 'eventemitter3' and export default class BaseStore instead of module.exports :)

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