diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2015-10-12 22:36:01 +0200 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-01-26 23:46:32 +0100 |
commit | 2c0e17cb977a1e8782799b337df8b1583d019906 (patch) | |
tree | 75563e440e9eac14950fa1a71a83e64df20e52d0 /src/web/js/stores/MenuStore.js | |
parent | fixing sqlalchemy resolving warning (diff) | |
download | newspipe-2c0e17cb977a1e8782799b337df8b1583d019906.tar.gz newspipe-2c0e17cb977a1e8782799b337df8b1583d019906.tar.bz2 newspipe-2c0e17cb977a1e8782799b337df8b1583d019906.zip |
bootstraping react
Diffstat (limited to 'src/web/js/stores/MenuStore.js')
-rw-r--r-- | src/web/js/stores/MenuStore.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js new file mode 100644 index 00000000..d7478091 --- /dev/null +++ b/src/web/js/stores/MenuStore.js @@ -0,0 +1,56 @@ +var JarrDispatcher = require('../dispatcher/JarrDispatcher'); +var MenuActionTypes = require('../constants/JarrConstants').MenuActionTypes; +var EventEmitter = require('events').EventEmitter; +var CHANGE_EVENT = 'change_menu'; +var assign = require('object-assign'); + + +var MenuStore = assign({}, EventEmitter.prototype, { + _datas: {filter: 'all', categories: [], all_unread_count: 0}, + getAll: function() { + return this._datas; + }, + setFilter: function(value) { + if(this._datas.filter != value) { + this._datas.filter = value; + this.emitChange(); + } + }, + readFeedArticle: function(feed_id) { + // TODO + }, + emitChange: function() { + this.emit(CHANGE_EVENT); + }, + addChangeListener: function(callback) { + this.on(CHANGE_EVENT, callback); + }, + removeChangeListener: function(callback) { + this.removeListener(CHANGE_EVENT, callback); + }, +}); + + +MenuStore.dispatchToken = JarrDispatcher.register(function(action) { + switch(action.type) { + case MenuActionTypes.RELOAD_MENU: + MenuStore._datas['categories'] = action.categories; + MenuStore._datas['all_unread_count'] = action.all_unread_count; + MenuStore.emitChange(); + break; + case MenuActionTypes.MENU_FILTER_ALL: + MenuStore.setFilter('all'); + break; + case MenuActionTypes.MENU_FILTER_UNREAD: + MenuStore.setFilter('unread'); + break; + case MenuActionTypes.MENU_FILTER_ERROR: + MenuStore.setFilter('error'); + break; + + default: + // do nothing + } +}); + +module.exports = MenuStore; |