Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.

Commit faccaa0

Browse files
authored
Merge pull request #36 from canalplus/add_global_state
Switch strategy view point (exit to enter) which fix issue strategy
2 parents 2e6ed13 + 10b9c26 commit faccaa0

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

dev/dev.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {connect, Provider} from 'react-redux';
55
import {Binder, StrapeBinder, keysInit, keysReducer, activeKeyBinder} from '../src';
66

77
const logger = store => next => action => {
8-
// console.group(action.type);
9-
// console.info('dispatching', action);
8+
console.group(action.type);
9+
console.info('dispatching', action);
1010
const result = next(action);
11-
// console.info('next state', store.getState());
12-
// console.groupEnd(action.type);
11+
console.info('next state', store.getState());
12+
console.groupEnd(action.type);
1313
return result;
1414
};
1515

src/redux/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export function _activeKeyBinder(binderId, id, memory = false) {
3939
} else {
4040
newState[binderId].selectedId = id || newState[binderId].selectedId;
4141
}
42+
newState.selectedId = newState[binderId].selectedId;
43+
newState.currentStrapeId = binderId;
4244
globalStore.dispatch({
4345
type: ACTIVE_KEYBINDER,
4446
state: newState,
@@ -127,6 +129,7 @@ export function updateSelectedId(binderId, selectedId, marginLeft) {
127129
const newState = clone(globalStore.getState()[NAME]);
128130
newState[binderId].selectedId = selectedId;
129131
newState[binderId].marginLeft = marginLeft;
132+
newState.selectedId = selectedId;
130133
globalStore.dispatch({
131134
type: UPDATE_SELECTED_KEY,
132135
state: newState,

src/redux/reducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from './actions';
77

88
const initialKeysSate = {
9+
selectedId: null,
10+
currentStrapeId: null,
911
getBinder: function(binderId) {
1012
return this[binderId] || {marginLeft: 0};
1113
},

test/redux/actions.spec.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('redux/actions.js', () => {
3232
sinon.test(function() {
3333
const store = createStore((state = {
3434
'@@keys': {
35-
binderId: {active: false},
36-
binderId2: {active: true},
35+
binderId: {active: false, elements: [{id: '1'}]},
36+
binderId2: {active: true, elements: [{id: '2'}]},
3737
},
3838
}) => state);
3939
listener._init({store: store}); // init globalStore
@@ -43,8 +43,10 @@ describe('redux/actions.js', () => {
4343
.withArgs({
4444
type: actions.ACTIVE_KEYBINDER,
4545
state: {
46-
binderId: {active: true, selectedId: undefined},
47-
binderId2: {active: false},
46+
binderId: {active: true, elements: {0: {id: '1'}}, selectedId: '1'},
47+
binderId2: {active: false, elements: {0: {id: '2'}}},
48+
currentStrapeId: 'binderId',
49+
selectedId: '1',
4850
},
4951
});
5052
actions._activeKeyBinder('binderId');
@@ -64,7 +66,7 @@ describe('redux/actions.js', () => {
6466
it('should keep in memory the selected Id when memory is true', sinon.test(function() {
6567
const store = createStore((state = {
6668
'@@keys': {
67-
binderId: {active: false},
69+
binderId: {active: false, selectedId: '2', elements: [{id: '1'}]},
6870
binderId2: {active: true, selectedId: '3'},
6971
},
7072
}) => state);
@@ -75,8 +77,10 @@ describe('redux/actions.js', () => {
7577
.withArgs({
7678
type: actions.ACTIVE_KEYBINDER,
7779
state: {
78-
binderId: {active: true, selectedId: undefined},
80+
binderId: {active: true, elements: {0: {id: '1'}}, selectedId: '2'},
7981
binderId2: {active: false, selectedId: '3'},
82+
currentStrapeId: 'binderId',
83+
selectedId: '2',
8084
},
8185
});
8286
actions._activeKeyBinder('binderId', null, true);
@@ -142,6 +146,7 @@ describe('redux/actions.js', () => {
142146
.withArgs({
143147
type: actions.UPDATE_SELECTED_KEY,
144148
state: {
149+
selectedId: 2,
145150
binderId: {active: false, selectedId: 2, marginLeft: 10},
146151
},
147152
});

0 commit comments

Comments
 (0)