Skip to content

Commit eb883e1

Browse files
committed
Implement action fitering
1 parent 0e6cd32 commit eb883e1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/browser/extension/inject/pageScript.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ window.devToolsExtension = function(next) {
99
let shouldInit = true;
1010
let actionsCount = 0;
1111

12-
function relay(type, state, action) {
12+
function relay(type, state, action, nextActionId) {
1313
const message = {
1414
payload: state,
1515
action: action || '',
16+
nextActionId: nextActionId || '',
1617
type: type,
1718
source: 'redux-page',
1819
init: shouldInit
@@ -59,23 +60,31 @@ window.devToolsExtension = function(next) {
5960
);
6061
}
6162

63+
function addFilter(state) {
64+
if (window.devToolsOptions.filter) {
65+
const { whitelist, blacklist } = window.devToolsOptions;
66+
state.filter = { whitelist, blacklist };
67+
}
68+
}
69+
6270
function isLimit() {
6371
if (window.devToolsOptions.limit && actionsCount > window.devToolsOptions.limit) {
6472
store.liftedStore.dispatch({type: 'COMMIT', timestamp: Date.now()});
6573
return true;
6674
}
67-
actionsCount++;
6875
return false;
6976
}
7077

7178
function subscriber(state = {}, action) {
7279
if (action && action.type) {
7380
setTimeout(() => {
7481
if (action.type === 'PERFORM_ACTION') {
82+
actionsCount++;
7583
if (isLimit() || isFiltered(action.action)) return state;
76-
relay('ACTION', store.getState(), action);
84+
relay('ACTION', store.getState(), action, actionsCount);
7785
} else {
78-
const liftedState = store.liftedStore.getState();
86+
let liftedState = store.liftedStore.getState();
87+
addFilter(liftedState);
7988
relay('STATE', liftedState);
8089
actionsCount = liftedState.nextActionId;
8190
}

src/browser/extension/utils/updateState.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import parseJSON from '../utils/parseJSON';
22

3-
function recompute(previousLiftedState, storeState, action) {
4-
let liftedState = { ...previousLiftedState };
5-
liftedState.stagedActionIds.push(liftedState.nextActionId);
6-
liftedState.actionsById[liftedState.nextActionId] = action;
7-
liftedState.nextActionId++;
3+
function recompute(previousLiftedState, storeState, action, nextActionId) {
4+
const actionId = nextActionId - 1;
5+
const liftedState = { ...previousLiftedState };
6+
liftedState.stagedActionIds.push(actionId);
7+
liftedState.actionsById[actionId] = action;
8+
liftedState.nextActionId = nextActionId;
89
liftedState.computedStates.push({ state: storeState });
910
liftedState.currentStateIndex++;
1011
return liftedState;
@@ -16,7 +17,7 @@ export default function updateState(store, request) {
1617

1718
switch (request.type) {
1819
case 'ACTION':
19-
const newState = recompute(store.liftedStore.getState(), payload, request.action);
20+
const newState = recompute(store.liftedStore.getState(), payload, request.action, request.nextActionId);
2021
store.liftedStore.setState(newState);
2122
return newState;
2223
case 'STATE':

0 commit comments

Comments
 (0)