aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/Dispatcher.es6.js
blob: 9bf708780392e4be71b6c5931dbbb1ab8d78bb4e (plain)
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
const PayloadSources = {
  VIEW_ACTION: "VIEW_ACTION",
  SERVER_ACTION: "SERVER_ACTION"
};

class Dispatcher {

  constructor() {
    this.callbacks = [];
  }

  register(callback){
    this.callbacks.push(callback);
  }

  unregister(callback){
    var index = this.callbacks.indexOf(f);
    if (index >= 0) {
      this.callbacks.splice(this.callbacks.indexOf(f), 1);
    }
  }

  dispatch(payload){
    console.debug("dispatch", payload);
    this.callbacks.forEach((callback) => {
        callback(payload);
    });
  }

}

AppDispatcher = new Dispatcher();
AppDispatcher.dispatchViewAction = function(action){
  action.actionSource = PayloadSources.VIEW_ACTION;
  this.dispatch(action);
};