Skip to content

Commit

Permalink
Merge pull request #408 from KleeGroup/fix-application-store
Browse files Browse the repository at this point in the history
Application Store : mode should be only 0 or 1 (not 2, -1, ...)
  • Loading branch information
Hartorn authored Sep 11, 2017
2 parents 883e1c9 + ae1a227 commit ffe1d86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "focus-core",
"version": "2.2.0-beta2",
"version": "2.2.0-beta3",
"description": "Focus library core part.",
"main": "index.js",
"babel": {
Expand Down
28 changes: 21 additions & 7 deletions src/history/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
let _navigate, _back, _start;

// Define the navigation functions depending on backbone or react-router
export const setNavigationFunctions = (navigate, back, start) => {
const setNavigationFunctions = (navigate, back, start) => {
_navigate = navigate;
_back = back;
_start = start;
}

export const navigate = (...args) => {
if(!_navigate) {
const navigate = (...args) => {
if (!_navigate) {
throw new Error('react-router or backbone URL Navigation was badly given in the setNavigationFunctions()')
}
_navigate(...args);
}

export const back = (...args) => {
if(!_back){
const back = (...args) => {
if (!_back) {
throw new Error('react-router or backbone Previous Page Navigation was badly given in the setNavigationFunctions()')
}
_back(...args);
}

export const start = (...args) => {
if(!_start) {
const start = (...args) => {
if (!_start) {
throw new Error('Backbone start router was badly given in the setNavigationFunctions()')
}
_start(...args);
}

export {
setNavigationFunctions,
navigate,
back,
start
}

export default {
setNavigationFunctions,
navigate,
back,
start
}
19 changes: 8 additions & 11 deletions src/store/application/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ class ApplicationStore extends CoreStore {
super(conf);
}
/**
* Update the mode value.
* @param {object} dataNode - The value of the data.
*/
* Update the mode value.
* @param {object} dataNode - The value of the data.
*/
updateMode(dataNode) {
let modeData = this.data.has('mode') ? this.data.get('mode') : Immutable.fromJS({});
let newModeValue = modeData.has(dataNode.newMode) ? (modeData.get(dataNode.newMode) + 1) : 1;
//Add a check to not have a negative mode, but it should not happen.
let previousModeValue = modeData.has(dataNode.previousMode) ? (modeData.get(dataNode.previousMode) - 1) : 0;
this.data = this.data.set('mode',
modeData.set(dataNode.newMode, newModeValue).set(dataNode.previousMode, previousModeValue)
);
const modeData = (this.data.has('mode') ? this.data.get('mode') : Immutable.fromJS({}))
.set(dataNode.newMode, 1)
.set(dataNode.previousMode, 0);
this.data = this.data.set('mode', modeData);
this.willEmit('mode:change');
}
}

export default ApplicationStore;
export default ApplicationStore;

0 comments on commit ffe1d86

Please sign in to comment.