Skip to content

Commit

Permalink
Reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
gosolivs committed May 11, 2019
1 parent 8257012 commit 19810d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 6 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var parse = JSON.parse
var eSync = '@sync'

/**
* Storeon module to sync state at different tabs of the browser
Expand All @@ -14,27 +14,22 @@ var crossTab = function (config) {
return function (store) {
store.on('@dispatch', function (_, e) {
if (e[0][0] === '@') {
if (e[0] === '@sync') sync = true
if (e[0] === '@changed') sync = false
sync = e[0] === eSync
return
}

if (sync) return

try {
localStorage[key] = JSON.stringify({
name: e[0],
data: e[1],
time: +new Date()
})
localStorage[key] = JSON.stringify([e[0], e[1], +new Date()])
} catch (er) {}
})

window.addEventListener('storage', function (e) {
if (e.key === key) {
var tip = parse(e.newValue)
store.dispatch('@sync')
store.dispatch(tip.name, tip.data)
var tip = JSON.parse(e.newValue)
store.dispatch(eSync)
store.dispatch(tip[0], tip[1])
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"size-limit": [
{
"path": "index.js",
"limit": "222 B"
"limit": "189 B"
}
],
"lint-staged": {
Expand Down

0 comments on commit 19810d4

Please sign in to comment.