mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-10 19:56:54 +03:00
Added SET_ACTIONS_ACTIVE, ability to set multiple actions between start and end indices to be active or skipped
This commit is contained in:
parent
a87564c9c4
commit
cbc1d0ecac
|
@ -1,4 +1,5 @@
|
|||
import difference from 'lodash/difference';
|
||||
import union from 'lodash/union';
|
||||
|
||||
export const ActionTypes = {
|
||||
PERFORM_ACTION: 'PERFORM_ACTION',
|
||||
|
@ -7,6 +8,7 @@ export const ActionTypes = {
|
|||
COMMIT: 'COMMIT',
|
||||
SWEEP: 'SWEEP',
|
||||
TOGGLE_ACTION: 'TOGGLE_ACTION',
|
||||
SET_ACTIONS_ACTIVE: 'SET_ACTIONS_ACTIVE',
|
||||
JUMP_TO_STATE: 'JUMP_TO_STATE',
|
||||
IMPORT_STATE: 'IMPORT_STATE'
|
||||
};
|
||||
|
@ -45,6 +47,10 @@ export const ActionCreators = {
|
|||
return { type: ActionTypes.TOGGLE_ACTION, id };
|
||||
},
|
||||
|
||||
setActionsActive(start, end, active=true) {
|
||||
return { type: ActionTypes.SET_ACTIONS_ACTIVE, start, end, active };
|
||||
},
|
||||
|
||||
jumpToState(index) {
|
||||
return { type: ActionTypes.JUMP_TO_STATE, index };
|
||||
},
|
||||
|
@ -219,6 +225,22 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer) {
|
|||
minInvalidatedStateIndex = stagedActionIds.indexOf(actionId);
|
||||
break;
|
||||
}
|
||||
case ActionTypes.SET_ACTIONS_ACTIVE: {
|
||||
// Toggle whether an action with given ID is skipped.
|
||||
// Being skipped means it is a no-op during the computation.
|
||||
const { start, end, active } = liftedAction;
|
||||
const actionIds = [];
|
||||
for (let i = start; i < end; i++) actionIds.push(i);
|
||||
if (active) {
|
||||
skippedActionIds = difference(skippedActionIds, actionIds);
|
||||
} else {
|
||||
skippedActionIds = union(skippedActionIds, actionIds);
|
||||
}
|
||||
|
||||
// Optimization: we know history before this action hasn't changed
|
||||
minInvalidatedStateIndex = stagedActionIds.indexOf(start);
|
||||
break;
|
||||
}
|
||||
case ActionTypes.JUMP_TO_STATE: {
|
||||
// Without recomputing anything, move the pointer that tell us
|
||||
// which state is considered the current one. Useful for sliders.
|
||||
|
|
|
@ -100,6 +100,23 @@ describe('instrument', () => {
|
|||
expect(store.getState()).toBe(1);
|
||||
});
|
||||
|
||||
it('should set multiple action skip', () => {
|
||||
// actionId 0 = @@INIT
|
||||
store.dispatch({ type: 'INCREMENT' });
|
||||
store.dispatch({ type: 'INCREMENT' });
|
||||
store.dispatch({ type: 'INCREMENT' });
|
||||
expect(store.getState()).toBe(3);
|
||||
|
||||
liftedStore.dispatch(ActionCreators.setActionsActive(1, 3, false));
|
||||
expect(store.getState()).toBe(1);
|
||||
|
||||
liftedStore.dispatch(ActionCreators.setActionsActive(0, 2, true));
|
||||
expect(store.getState()).toBe(2);
|
||||
|
||||
liftedStore.dispatch(ActionCreators.setActionsActive(0, 1, true));
|
||||
expect(store.getState()).toBe(2);
|
||||
});
|
||||
|
||||
it('should sweep disabled actions', () => {
|
||||
// actionId 0 = @@INIT
|
||||
store.dispatch({ type: 'INCREMENT' });
|
||||
|
|
Loading…
Reference in New Issue
Block a user