From 19810d4a61c29fa9194598c075e065e0d1e9efb7 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Sat, 11 May 2019 12:54:30 +0300 Subject: [PATCH] Reduce size --- index.js | 17 ++++++----------- package.json | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 93058b4..44a352d 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var parse = JSON.parse +var eSync = '@sync' /** * Storeon module to sync state at different tabs of the browser @@ -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]) } }) } diff --git a/package.json b/package.json index e4c3309..a5470b7 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "size-limit": [ { "path": "index.js", - "limit": "222 B" + "limit": "189 B" } ], "lint-staged": {