You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
939 B
22 lines
939 B
export default function createTransform( // @NOTE inbound: transform state coming from redux on its way to being serialized and stored |
|
inbound, // @NOTE outbound: transform state coming from storage, on its way to be rehydrated into redux |
|
outbound) { |
|
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
|
var whitelist = config.whitelist || null; |
|
var blacklist = config.blacklist || null; |
|
|
|
function whitelistBlacklistCheck(key) { |
|
if (whitelist && whitelist.indexOf(key) === -1) return true; |
|
if (blacklist && blacklist.indexOf(key) !== -1) return true; |
|
return false; |
|
} |
|
|
|
return { |
|
in: function _in(state, key, fullState) { |
|
return !whitelistBlacklistCheck(key) && inbound ? inbound(state, key, fullState) : state; |
|
}, |
|
out: function out(state, key, fullState) { |
|
return !whitelistBlacklistCheck(key) && outbound ? outbound(state, key, fullState) : state; |
|
} |
|
}; |
|
} |