created navigation store

This commit is contained in:
Senad Uka
2015-01-27 05:47:10 +01:00
parent 5c9b2f99ee
commit c8a399b98f
7 changed files with 86 additions and 34 deletions

View File

@@ -0,0 +1,51 @@
var AppDispatcher = require('../dispatcher/appDispatcher');
var EventEmitter = require('events').EventEmitter;
var NavigationConstants = require('../constants/navigationConstants')
var _ = require('underscore');
// Extend ItemStore with EventEmitter to add eventing capabilities
var NavigationStore = _.extend({}, EventEmitter.prototype, {
// Emit Change event
emitChange: function() {
console.log("NavigationStore change!");
this.emit('change');
},
// Add change listener
addChangeListener: function(callback) {
this.on('change', callback);
},
// Remove change listener
removeChangeListener: function(callback) {
this.removeListener('change', callback);
}
});
// Register callback with AppDispatcher
AppDispatcher.register(function(payload) {
var action = payload.action;
switch(action.actionType) {
case NavigationConstants.CHANGE_URL:
var router = require('../router');
router.transitionTo(action.url);
break;
default:
return true;
}
// If action was responded to, emit change event
NavigationStore.emitChange();
return true;
});
module.exports = NavigationStore;