-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (29 loc) · 973 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var EventEmitter = require('events').EventEmitter;
var ObjectAssign = require('object-assign');
var CHANGE_EVENT = 'change';
var FluxStore = ObjectAssign({}, EventEmitter.prototype, {
dispatchToken: undefined,
registerDispatcher: function (Dispatcher) {
var callback = this.onDispatcherAction.bind(this);
this.dispatchToken = Dispatcher.register(callback);
},
emitChange: function () {
this.emit(CHANGE_EVENT);
},
addChangeListener: function (callback) {
this.on(CHANGE_EVENT, callback);
},
removeChangeListener: function (callback) {
this.removeListener(CHANGE_EVENT, callback);
},
extend: function (stuff) {
var newStore = ObjectAssign({}, FluxStore, stuff);
if (stuff.dispatcher) {
newStore.registerDispatcher(stuff.dispatcher);
}
delete newStore.extend;
return newStore;
}
});
module.exports = FluxStore;