forked from rt2zz/redux-persist-crosstab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (18 loc) · 721 Bytes
/
Copy pathindex.js
File metadata and controls
22 lines (18 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var constants = require('redux-persist/constants')
var KEY_PREFIX = constants.KEY_PREFIX
module.exports = function(persistor, config){
var config = config || {}
var blacklist = config.blacklist || false
var whitelist = config.whitelist || false
window.addEventListener('storage', handleStorageEvent, false)
function handleStorageEvent(e){
if(e.key.indexOf(KEY_PREFIX) === 0){
var keyspace = e.key.substr(KEY_PREFIX.length)
if(whitelist && whitelist.indexOf(keyspace) === -1){ return }
if(blacklist && blacklist.indexOf(keyspace) !== -1){ return }
var statePartial = {}
statePartial[keyspace] = e.newValue
persistor.rehydrate(statePartial, {serial: true})
}
}
}