aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/stores/SettingsStore.es6.js
blob: 7f3a68372fbaeb478645da6e91f02f4db50b8ca8 (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
37
38
39
40
41
42
class _SettingsStore extends EventEmitter {
	constructor() {
		/*jshint validthis: true */
		super();
		this.settings = { version: "0.12", showEventLog: true }; //FIXME: Need to get that from somewhere.
	}
	getSettings() {
		return this.settings;
	}
	handle(action) {
		switch (action.actionType) {
			case ActionTypes.SETTINGS_UPDATE:
				this.settings = action.settings;
				this.emit("change");
				break;
			default:
				return;
		}
	}
}
var SettingsStore = new _SettingsStore();
AppDispatcher.register(SettingsStore.handle.bind(SettingsStore));


var SettingsMixin = {
	getInitialState(){
		return {
			settings: SettingsStore.getSettings()
		};
	},
    componentDidMount(){
        SettingsStore.addListener("change", this._onSettingsChange);
    },
    componentWillUnmount(){
        SettingsStore.removeListener("change", this._onSettingsChange);
    },
    _onSettingsChange(){
    	this.setState({
    		settings: SettingsStore.getSettings()
    	});
    }
};