Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap-term-changes: Rename black/white according to SAP #1415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const App = () => {
- arguments
- [**config**](https://github.com/rt2zz/redux-persist/blob/master/src/types.js#L13-L27) *object*
- required config: `key, storage`
- notable other config: `whitelist, blacklist, version, stateReconciler, debug`
- notable other config: `allowlist, denylist, version, stateReconciler, debug`
- **reducer** *function*
- any reducer will work, typically this would be the top level reducer returned by `combineReducers`
- returns an enhanced reducer
Expand Down Expand Up @@ -181,26 +181,26 @@ Redux persist ships with react integration as a convenience. The `PersistGate` c
1. `loading` prop: The provided loading value will be rendered until persistence is complete at which point children will be rendered.
2. function children: The function will be invoked with a single `bootstrapped` argument. When bootstrapped is true, persistence is complete and it is safe to render the full app. This can be useful for adding transition animations.

## Blacklist & Whitelist
## Denylist & Allowlist
By Example:
```js
// BLACKLIST
// DENYLIST
const persistConfig = {
key: 'root',
storage: storage,
blacklist: ['navigation'] // navigation will not be persisted
denylist: ['navigation'] // navigation will not be persisted
};

// WHITELIST
// ALLOWLIST
const persistConfig = {
key: 'root',
storage: storage,
whitelist: ['navigation'] // only navigation will be persisted
allowlist: ['navigation'] // only navigation will be persisted
};
```

## Nested Persists
Nested persist can be useful for including different storage adapters, code splitting, or deep filtering. For example while blacklist and whitelist only work one level deep, but we can use a nested persist to blacklist a deeper value:
Nested persist can be useful for including different storage adapters, code splitting, or deep filtering. For example while denylist and allowlist only work one level deep, but we can use a nested persist to denylist a deeper value:
```js
import { combineReducers } from 'redux'
import { persistReducer } from 'redux-persist'
Expand All @@ -211,13 +211,13 @@ import { authReducer, otherReducer } from './reducers'
const rootPersistConfig = {
key: 'root',
storage: storage,
blacklist: ['auth']
denylist: ['auth']
}

const authPersistConfig = {
key: 'auth',
storage: storage,
blacklist: ['somethingTemporary']
denylist: ['somethingTemporary']
}

const rootReducer = combineReducers({
Expand Down Expand Up @@ -265,7 +265,7 @@ const SetTransform = createTransform(
return { ...outboundState, mySet: new Set(outboundState.mySet) };
},
// define which reducers this transform gets called for.
{ whitelist: ['someReducer'] }
{ allowlist: ['someReducer'] }
);

export default SetTransform;
Expand Down
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ The Persistor is a redux store unto itself, plus
key: string, // the key for the persist
storage: Object, // the storage adapter, following the AsyncStorage api
version?: number, // the state version as an integer (defaults to -1)
blacklist?: Array<string>, // do not persist these keys
whitelist?: Array<string>, // only persist these keys
denylist?: Array<string>, // do not persist these keys
allowlist?: Array<string>, // only persist these keys
migrate?: (Object, number) => Promise<Object>,
transforms?: Array<Transform>,
throttle?: number, // ms to throttle state writes
Expand Down
14 changes: 7 additions & 7 deletions src/createPersistoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { KeyAccessState } from './types'

export default function createPersistoid(config: PersistConfig<any>): Persistoid {
// defaults
const blacklist: string[] | null = config.blacklist || null
const whitelist: string[] | null = config.whitelist || null
const denylist: string[] | null = config.denylist || null
const allowlist: string[] | null = config.allowlist || null
const transforms = config.transforms || []
const throttle = config.throttle || 0
const storageKey = `${
Expand All @@ -34,7 +34,7 @@ export default function createPersistoid(config: PersistConfig<any>): Persistoid
const update = (state: KeyAccessState) => {
// add any changed keys to the queue
Object.keys(state).forEach(key => {
if (!passWhitelistBlacklist(key)) return // is keyspace ignored? noop
if (!passAllowlistDenylist(key)) return // is keyspace ignored? noop
if (lastState[key] === state[key]) return // value unchanged? noop
if (keysToProcess.indexOf(key) !== -1) return // is key already queued? noop
keysToProcess.push(key) // add key to queue
Expand All @@ -45,7 +45,7 @@ export default function createPersistoid(config: PersistConfig<any>): Persistoid
Object.keys(lastState).forEach(key => {
if (
state[key] === undefined &&
passWhitelistBlacklist(key) &&
passAllowlistDenylist(key) &&
keysToProcess.indexOf(key) === -1 &&
lastState[key] !== undefined
) {
Expand Down Expand Up @@ -108,10 +108,10 @@ export default function createPersistoid(config: PersistConfig<any>): Persistoid
.catch(onWriteFail)
}

function passWhitelistBlacklist(key: string) {
if (whitelist && whitelist.indexOf(key) === -1 && key !== '_persist')
function passAllowlistDenylist(key: string) {
if (allowlist && allowlist.indexOf(key) === -1 && key !== '_persist')
return false
if (blacklist && blacklist.indexOf(key) !== -1) return false
if (denylist && denylist.indexOf(key) !== -1) return false
return true
}

Expand Down
18 changes: 9 additions & 9 deletions src/createTransform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
type TransformConfig = {
whitelist?: Array<string>,
blacklist?: Array<string>,
allowlist?: Array<string>,
denylist?: Array<string>,
}

export default function createTransform(
Expand All @@ -13,22 +13,22 @@ export default function createTransform(
outbound: Function,
config: TransformConfig = {}
): any {
const whitelist = config.whitelist || null
const blacklist = config.blacklist || null
const allowlist = config.allowlist || null
const denylist = config.denylist || null

function whitelistBlacklistCheck(key: string) {
if (whitelist && whitelist.indexOf(key) === -1) return true
if (blacklist && blacklist.indexOf(key) !== -1) return true
function allowlistDenylistCheck(key: string) {
if (allowlist && allowlist.indexOf(key) === -1) return true
if (denylist && denylist.indexOf(key) !== -1) return true
return false
}

return {
in: (state: Record<string, unknown>, key: string, fullState: Record<string, unknown>) =>
!whitelistBlacklistCheck(key) && inbound
!allowlistDenylistCheck(key) && inbound
? inbound(state, key, fullState)
: state,
out: (state: Record<string, unknown>, key: string, fullState: Record<string, unknown>) =>
!whitelistBlacklistCheck(key) && outbound
!allowlistDenylistCheck(key) && outbound
? outbound(state, key, fullState)
: state,
}
Expand Down
16 changes: 8 additions & 8 deletions src/integration/getStoredStateMigrateV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type V4Config = {
serialize: boolean,
keyPrefix?: string,
transforms?: Array<Transform<any, any>>,
blacklist?: Array<string>,
whitelist?: Array<string>,
denylist?: Array<string>,
allowlist?: Array<string>,
}

export default function getStoredState(v4Config: V4Config) {
Expand Down Expand Up @@ -105,8 +105,8 @@ function getStoredStateV4(v4Config: V4Config) {
v4Config.serialize === false
? (data: any) => data
: (serial: string) => JSON.parse(serial)
const blacklist = v4Config.blacklist || []
const whitelist = v4Config.whitelist || false
const denylist = v4Config.denylist || []
const allowlist = v4Config.allowlist || false
const transforms = v4Config.transforms || []
const keyPrefix =
v4Config.keyPrefix !== undefined ? v4Config.keyPrefix : KEY_PREFIX
Expand All @@ -130,7 +130,7 @@ function getStoredStateV4(v4Config: V4Config) {
const persistKeys = allKeys
.filter(key => key.indexOf(keyPrefix) === 0)
.map(key => key.slice(keyPrefix.length))
const keysToRestore = persistKeys.filter(passWhitelistBlacklist)
const keysToRestore = persistKeys.filter(passAllowlistDenylist)

const restoreCount = keysToRestore.length
if (restoreCount === 0) resolve(undefined)
Expand Down Expand Up @@ -169,9 +169,9 @@ function getStoredStateV4(v4Config: V4Config) {
return state
}

function passWhitelistBlacklist(key: string) {
if (whitelist && whitelist.indexOf(key) === -1) return false
if (blacklist.indexOf(key) !== -1) return false
function passAllowlistDenylist(key: string) {
if (allowlist && allowlist.indexOf(key) === -1) return false
if (denylist.indexOf(key) !== -1) return false
return true
}

Expand Down
4 changes: 2 additions & 2 deletions src/persistStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export default function persistStore(
if (process.env.NODE_ENV !== 'production') {
const optionsToTest: OptionToTestObject = options || {}
const bannedKeys = [
'blacklist',
'whitelist',
'denylist',
'allowlist',
'transforms',
'storage',
'keyPrefix',
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface PersistConfig<S, RS = any, HSS = any, ESS = any> {
* @deprecated keyPrefix is going to be removed in v6.
*/
keyPrefix?: string;
blacklist?: Array<string>;
whitelist?: Array<string>;
denylist?: Array<string>;
allowlist?: Array<string>;
transforms?: Array<Transform<HSS, ESS, S, RS>>;
throttle?: number;
migrate?: PersistMigrate;
Expand Down