-
Notifications
You must be signed in to change notification settings - Fork 0
/
staticflux.js
42 lines (35 loc) · 833 Bytes
/
staticflux.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
var Rx = require('rx');
function Singleton(o) {
o.__defineGetter__('instance', function() {
if(!o._instance){
o._instance = new o();
}
return o._instance;
});
}
class Action {
static create(){
var subject = new Rx.Subject();
var fn = function(value) {
subject.onNext(value)
}
Object.setPrototypeOf(fn,subject);
return fn;
}
}
class Store {
constructor(state){
this.subject = new Rx.ReplaySubject(1);
this.updateState(state);
}
updateState(state){
this.state = state;
this.subject.onNext(state);
}
subscribe(handler){
this.subject.subscribe(handler);
}
}
module.exports.Action = Action;
module.exports.Store = Store;
module.exports.Singleton = Singleton;