Skip to content

Commit c12fd90

Browse files
committed
(optim): return early if white|blacklist doesn't exist
- more importantly, makes the logic a little simpler / easier to read
1 parent a4d8f16 commit c12fd90

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/transforms/blacklist.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export function blacklistKeys (blacklist?: Array<string>): ITransform {
44
const blacklistDict = arrToDict(blacklist)
55

66
return {toStorage: function blacklistTransform (snapshot) {
7+
if (!blacklist) { return snapshot }
8+
79
Object.keys(snapshot).forEach((key) => {
8-
if (blacklist && blacklistDict[key]) {
9-
delete snapshot[key]
10-
}
10+
if (blacklistDict[key]) { delete snapshot[key] }
1111
})
1212
return snapshot
1313
}}

src/transforms/whitelist.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export function whitelistKeys (whitelist?: Array<string>): ITransform {
44
const whitelistDict = arrToDict(whitelist)
55

66
return {toStorage: function whitelistTransform (snapshot) {
7+
if (!whitelist) { return snapshot }
8+
79
Object.keys(snapshot).forEach((key) => {
8-
if (whitelist && !whitelistDict[key]) {
9-
delete snapshot[key]
10-
}
10+
if (!whitelistDict[key]) { delete snapshot[key] }
1111
})
1212
return snapshot
1313
}}

0 commit comments

Comments
 (0)