Skip to content

Commit

Permalink
fix(StoreDevTools): rename action list filters
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

`actionsWhitelist` is renamed to `actionsSafelist`
`actionsBlacklist` is renamed to `actionsBlocklist`

BEFORE:

```ts
StoreDevtoolsModule.instrument({
  actionsWhitelist: ['...'],
  actionsBlacklist: ['...']
})

AFTER:

```ts
StoreDevtoolsModule.instrument({
  actionsSafelist: ['...'],
  actionsBlocklist: ['...']
})
```
  • Loading branch information
timdeschryver committed Feb 27, 2019
1 parent 5fbcb3c commit b9122fa
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 61 deletions.
20 changes: 10 additions & 10 deletions modules/store-devtools/spec/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,23 @@ describe('DevtoolsExtension', () => {
});
});

describe('with Action and actionsBlacklist', () => {
describe('with Action and actionsBlocklist', () => {
const NORMAL_ACTION = 'NORMAL_ACTION';
const BLACKLISTED_ACTION = 'BLACKLISTED_ACTION';
const BLOCKED_ACTION = 'BLOCKED_ACTION';

beforeEach(() => {
devtoolsExtension = new DevtoolsExtension(
reduxDevtoolsExtension,
createConfig({
actionsBlacklist: [BLACKLISTED_ACTION],
actionsBlocklist: [BLOCKED_ACTION],
}),
<any>null
);
// Subscription needed or else extension connection will not be established.
devtoolsExtension.actions$.subscribe(() => null);
});

it('should ignore blacklisted action', () => {
it('should ignore the blocked action', () => {
const options = createOptions();
const state = createState();

Expand All @@ -403,30 +403,30 @@ describe('DevtoolsExtension', () => {
state
);
devtoolsExtension.notify(
new PerformAction({ type: BLACKLISTED_ACTION }, 1234567),
new PerformAction({ type: BLOCKED_ACTION }, 1234567),
state
);
expect(extensionConnection.send).toHaveBeenCalledTimes(2);
});
});

describe('with Action and actionsWhitelist', () => {
describe('with Action and actionsSafelist', () => {
const NORMAL_ACTION = 'NORMAL_ACTION';
const WHITELISTED_ACTION = 'WHITELISTED_ACTION';
const SAFE_ACTION = 'SAFE_ACTION';

beforeEach(() => {
devtoolsExtension = new DevtoolsExtension(
reduxDevtoolsExtension,
createConfig({
actionsWhitelist: [WHITELISTED_ACTION],
actionsSafelist: [SAFE_ACTION],
}),
<any>null
);
// Subscription needed or else extension connection will not be established.
devtoolsExtension.actions$.subscribe(() => null);
});

it('should only keep whitelisted action', () => {
it('should only keep the safe action', () => {
const options = createOptions();
const state = createState();

Expand All @@ -439,7 +439,7 @@ describe('DevtoolsExtension', () => {
state
);
devtoolsExtension.notify(
new PerformAction({ type: WHITELISTED_ACTION }, 1234567),
new PerformAction({ type: SAFE_ACTION }, 1234567),
state
);
expect(extensionConnection.send).toHaveBeenCalledTimes(1);
Expand Down
8 changes: 4 additions & 4 deletions modules/store-devtools/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe('Devtools Integration', () => {
devtools.refresh();
});

it('should not throw if actions are blacklisted', (done: any) => {
it('should not throw if actions are blocked', (done: any) => {
const { store, devtools } = setup({
actionsBlacklist: ['FOO'],
actionsBlocklist: ['FOO'],
});
store.subscribe();
devtools.dispatcher.subscribe((action: Action) => {
Expand All @@ -80,9 +80,9 @@ describe('Devtools Integration', () => {
devtools.refresh();
});

it('should not throw if actions are whitelisted', (done: any) => {
it('should not throw if actions are safe', (done: any) => {
const { store, devtools } = setup({
actionsWhitelist: ['BAR'],
actionsSafelist: ['BAR'],
});
store.subscribe();
devtools.dispatcher.subscribe((action: Action) => {
Expand Down
8 changes: 4 additions & 4 deletions modules/store-devtools/spec/store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ describe('Store Devtools', () => {
expect(fixture.getState()).toBe(5);
});

it('should respect the blacklist option', () => {
it('should respect the blocked option', () => {
const fixture = createStore(counter, {
actionsBlacklist: ['INCREMENT'],
actionsBlocklist: ['INCREMENT'],
});

expect(fixture.getState()).toBe(0);
Expand Down Expand Up @@ -517,9 +517,9 @@ describe('Store Devtools', () => {
expect(fixture.getState()).toBe(5);
});

it('should respect the whitelist option', () => {
it('should respect the safe option', () => {
const fixture = createStore(counter, {
actionsWhitelist: ['DECREMENT'],
actionsSafelist: ['DECREMENT'],
});

expect(fixture.getState()).toBe(0);
Expand Down
4 changes: 2 additions & 2 deletions modules/store-devtools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class StoreDevtoolsConfig {
serialize?: boolean | SerializationOptions;
logOnly?: boolean;
features?: any;
actionsBlacklist?: string[];
actionsWhitelist?: string[];
actionsBlocklist?: string[];
actionsSafelist?: string[];
predicate?: Predicate;
}

Expand Down
51 changes: 28 additions & 23 deletions modules/store-devtools/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import * as Actions from './actions';
import { STORE_DEVTOOLS_CONFIG, StoreDevtoolsConfig } from './config';
import { DevtoolsExtension } from './extension';
import { LiftedState, liftInitialState, liftReducerWith } from './reducer';
import { liftAction, unliftState, shouldFilterActions, filterLiftedState } from './utils';
import {
liftAction,
unliftState,
shouldFilterActions,
filterLiftedState,
} from './utils';
import { DevtoolsDispatcher } from './devtools-dispatcher';
import { PERFORM_ACTION } from './actions';

Expand Down Expand Up @@ -73,25 +78,25 @@ export class StoreDevtools implements Observer<any> {
state: LiftedState;
action: any;
}
>(
({ state: liftedState }, [action, reducer]) => {
let reducedLiftedState = reducer(liftedState, action);
// On full state update
// If we have actions filters, we must filter completly our lifted state to be sync with the extension
if (action.type !== PERFORM_ACTION && shouldFilterActions(config)) {
reducedLiftedState = filterLiftedState(
reducedLiftedState,
config.predicate,
config.actionsWhitelist,
config.actionsBlacklist
);
}
// Extension should be sent the sanitized lifted state
extension.notify(action, reducedLiftedState);
return { state: reducedLiftedState, action };
},
{ state: liftedInitialState, action: null as any }
)
>(
({ state: liftedState }, [action, reducer]) => {
let reducedLiftedState = reducer(liftedState, action);
// On full state update
// If we have actions filters, we must filter completly our lifted state to be sync with the extension
if (action.type !== PERFORM_ACTION && shouldFilterActions(config)) {
reducedLiftedState = filterLiftedState(
reducedLiftedState,
config.predicate,
config.actionsSafelist,
config.actionsBlocklist
);
}
// Extension should be sent the sanitized lifted state
extension.notify(action, reducedLiftedState);
return { state: reducedLiftedState, action };
},
{ state: liftedInitialState, action: null as any }
)
)
.subscribe(({ state, action }) => {
liftedStateSubject.next(state);
Expand All @@ -109,7 +114,7 @@ export class StoreDevtools implements Observer<any> {

const liftedState$ = liftedStateSubject.asObservable() as Observable<
LiftedState
>;
>;
const state$ = liftedState$.pipe(map(unliftState));

this.extensionStartSubscription = extensionStartSubscription;
Expand All @@ -127,9 +132,9 @@ export class StoreDevtools implements Observer<any> {
this.dispatcher.next(action);
}

error(error: any) { }
error(error: any) {}

complete() { }
complete() {}

performAction(action: any) {
this.dispatch(new Actions.PerformAction(action, +Date.now()));
Expand Down
4 changes: 2 additions & 2 deletions modules/store-devtools/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export class DevtoolsExtension {
currentState,
action,
this.config.predicate,
this.config.actionsWhitelist,
this.config.actionsBlacklist
this.config.actionsSafelist,
this.config.actionsBlocklist
)
) {
return;
Expand Down
4 changes: 2 additions & 2 deletions modules/store-devtools/src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ export function liftReducerWith(
liftedState.computedStates[currentStateIndex],
liftedAction,
options.predicate,
options.actionsWhitelist,
options.actionsBlacklist
options.actionsSafelist,
options.actionsBlocklist
))
) {
// If recording is paused or if the action should be ignored, overwrite the last state
Expand Down
26 changes: 13 additions & 13 deletions modules/store-devtools/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function unliftState(liftedState: LiftedState) {
const { computedStates, currentStateIndex } = liftedState;

// At start up NgRx dispatches init actions,
// When these init actions are being filtered out by the predicate or black/white list options
// When these init actions are being filtered out by the predicate or safe/block list options
// we don't have a complete computed states yet.
// At this point it could happen that we're out of bounds, when this happens we fall back to the last known state
if (currentStateIndex >= computedStates.length) {
Expand Down Expand Up @@ -112,7 +112,7 @@ export function sanitizeState(
* Read the config and tell if actions should be filtered
*/
export function shouldFilterActions(config: StoreDevtoolsConfig) {
return config.predicate || config.actionsWhitelist || config.actionsBlacklist;
return config.predicate || config.actionsSafelist || config.actionsBlocklist;
}

/**
Expand All @@ -121,8 +121,8 @@ export function shouldFilterActions(config: StoreDevtoolsConfig) {
export function filterLiftedState(
liftedState: LiftedState,
predicate?: Predicate,
whitelist?: string[],
blacklist?: string[]
safelist?: string[],
blocklist?: string[]
): LiftedState {
const filteredStagedActionIds: number[] = [];
const filteredActionsById: LiftedActions = {};
Expand All @@ -136,8 +136,8 @@ export function filterLiftedState(
liftedState.computedStates[idx],
liftedAction,
predicate,
whitelist,
blacklist
safelist,
blocklist
)
) {
return;
Expand All @@ -161,13 +161,13 @@ export function isActionFiltered(
state: any,
action: LiftedAction,
predicate?: Predicate,
whitelist?: string[],
blacklist?: string[]
safelist?: string[],
blockedlist?: string[]
) {
const predicateMatch = predicate && !predicate(state, action.action);
const whitelistMatch =
whitelist && !action.action.type.match(whitelist.join('|'));
const blacklistMatch =
blacklist && action.action.type.match(blacklist.join('|'));
return predicateMatch || whitelistMatch || blacklistMatch;
const safelistMatch =
safelist && !action.action.type.match(safelist.join('|'));
const blocklistMatch =
blockedlist && action.action.type.match(blockedlist.join('|'));
return predicateMatch || safelistMatch || blocklistMatch;
}
2 changes: 1 addition & 1 deletion projects/ngrx.io/content/guide/store-devtools/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function - takes `state` object and index as arguments, and should return a `sta

For more detailed information see [Redux DevTools Serialize](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#serialize)

### `actionsBlacklist` / `actionsWhitelist`
### `actionsSafelist` / `actionsBlocklist`

array of strings as regex - actions types to be hidden / shown in the monitors, [more information here](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#actionsblacklist--actionswhitelist).

Expand Down

0 comments on commit b9122fa

Please sign in to comment.