/
AppStore.js
44 lines (31 loc) · 850 Bytes
/
AppStore.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
44
var _ = require('lodash');
var Signals = require('signals');
var termcolors = require('termcolors');
var AppDispatcher = require('../dispatchers/AppDispatcher');
var AppConstants = require('../constants/AppConstants');
var url = require('../formats/url');
var _colors = url.import(location.hash);
if (_colors === false) {
_colors = _.clone(termcolors.defaults.colors);
}
var AppStore = Signals.convert({
getColors: function () {
return _colors;
}
});
AppDispatcher.register(function (payload) {
var action = payload.action;
switch (action.actionType) {
case AppConstants.SET_ALL_COLORS:
_colors = action.colors;
break;
default:
return true;
}
AppStore.emit('change');
return true;
});
AppStore.on('change', function () {
location.hash = url.export(_colors);
});
module.exports = AppStore;