mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 17:00:04 +02:00
[Flux] Initial flux land
This commit is contained in:
parent
5df3d43c4f
commit
eba404c595
5 changed files with 105 additions and 3 deletions
18
src/js/actions/LocaleActions.js
Normal file
18
src/js/actions/LocaleActions.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
var AppConstants = require('../constants/AppConstants');
|
||||
var AppDispatcher = require('../dispatcher/AppDispatcher');
|
||||
|
||||
var ActionTypes = AppConstants.ActionTypes;
|
||||
|
||||
var LocaleActions = {
|
||||
|
||||
changeLocale: function(newLocale) {
|
||||
AppDispatcher.handleViewAction({
|
||||
type: ActionTypes.CHANGE_LOCALE,
|
||||
locale: newLocale
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = LocaleActions;
|
16
src/js/constants/AppConstants.js
Normal file
16
src/js/constants/AppConstants.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
var keyMirror = require('react/lib/keyMirror');
|
||||
|
||||
module.exports = {
|
||||
|
||||
ActionTypes: keyMirror({
|
||||
SUBMIT_COMMAND: null,
|
||||
CHANGE_LOCALE: null
|
||||
}),
|
||||
|
||||
PayloadSources: keyMirror({
|
||||
VIEW_ACTION: null,
|
||||
URI_ACTION: null
|
||||
})
|
||||
};
|
24
src/js/dispatcher/AppDispatcher.js
Normal file
24
src/js/dispatcher/AppDispatcher.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
var AppConstants = require('../constants/AppConstants');
|
||||
var Dispatcher = require('flux').Dispatcher;
|
||||
|
||||
var PayloadSources = AppConstants.PayloadSources;
|
||||
|
||||
var AppDispatcher = new Dispatcher();
|
||||
|
||||
AppDispatcher.handleViewAction = function(action) {
|
||||
this.dispatch({
|
||||
source: PayloadSources.VIEW_ACTION,
|
||||
action: action
|
||||
});
|
||||
};
|
||||
|
||||
AppDispatcher.handleURIAction = function(action) {
|
||||
this.dispatch({
|
||||
source: PayloadSources.URI_ACTION,
|
||||
action: action
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = AppDispatcher;
|
42
src/js/stores/LocaleStore.js
Normal file
42
src/js/stores/LocaleStore.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
var AppConstants = require('../constants/AppConstants');
|
||||
var AppDispatcher = require('../dispatcher/AppDispatcher');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var assign = require('object-assign');
|
||||
|
||||
var ActionTypes = AppConstants.ActionTypes;
|
||||
var CHANGE_EVENT = 'change';
|
||||
|
||||
var _locale = 'en_US';
|
||||
var LocaleStore = assign({}, EventEmitter.prototype, {
|
||||
|
||||
subscribe: function(cb) {
|
||||
this.on(CHANGE_EVENT, cb);
|
||||
},
|
||||
|
||||
unsubscribe: function(cb) {
|
||||
this.removeListener(CHANGE_EVENT, cb);
|
||||
},
|
||||
|
||||
getLocale: function() {
|
||||
return _locale;
|
||||
},
|
||||
|
||||
dispatchToken: AppDispatcher.register(function(payload) {
|
||||
var action = payload.action;
|
||||
var shouldInform = false;
|
||||
|
||||
switch (action.type) {
|
||||
case ActionTypes.CHANGE_LOCALE:
|
||||
}
|
||||
|
||||
if (shouldInform) {
|
||||
this.emit(CHANGE_EVENT);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
module.exports = LocaleStore;
|
Loading…
Add table
Add a link
Reference in a new issue