redux-state-sync
Advanced tools
Comparing version 1.1.1 to 1.2.1
@@ -38,5 +38,9 @@ 'use strict'; | ||
// generate current window unique id | ||
var _WINDOW_STATE_SYNC_ID = guid(); | ||
function generateUuidForAction(action) { | ||
var stampedAction = action; | ||
stampedAction.$uuid = guid(); | ||
stampedAction.$wuid = _WINDOW_STATE_SYNC_ID; | ||
return stampedAction; | ||
@@ -102,2 +106,8 @@ } | ||
var stampedAction = JSON.parse(event.newValue); | ||
// ignore if this action is triggered by this window | ||
// IE bug https://stackoverflow.com/questions/18265556/why-does-internet-explorer-fire-the-window-storage-event-on-the-window-that-st | ||
if (stampedAction.$wuid === _WINDOW_STATE_SYNC_ID) { | ||
return; | ||
} | ||
// ignore other values that saved to localstorage. | ||
@@ -104,0 +114,0 @@ if (stampedAction.$uuid) { |
@@ -121,5 +121,9 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
// generate current window unique id | ||
var _WINDOW_STATE_SYNC_ID = guid(); | ||
function generateUuidForAction(action) { | ||
var stampedAction = action; | ||
stampedAction.$uuid = guid(); | ||
stampedAction.$wuid = _WINDOW_STATE_SYNC_ID; | ||
return stampedAction; | ||
@@ -185,2 +189,8 @@ } | ||
var stampedAction = JSON.parse(event.newValue); | ||
// ignore if this action is triggered by this window | ||
// IE bug https://stackoverflow.com/questions/18265556/why-does-internet-explorer-fire-the-window-storage-event-on-the-window-that-st | ||
if (stampedAction.$wuid === _WINDOW_STATE_SYNC_ID) { | ||
return; | ||
} | ||
// ignore other values that saved to localstorage. | ||
@@ -187,0 +197,0 @@ if (stampedAction.$uuid) { |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.reduxStateSync=e():t.reduxStateSync=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";function n(){return o()+o()+"-"+o()+"-"+o()+"-"+o()+"-"+o()+o()+o()}function o(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function i(t){var e=t;return e.$uuid=n(),e}function u(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d,r=!1,n=function(){return!0};e.predicate&&"function"==typeof e.predicate?n=e.predicate:Array.isArray(e.ignore)&&(n=function(t){return e.ignore.indexOf(t)<0}),e.initiateWithState&&t.dispatch(p()),window.addEventListener("storage",function(e){try{var o=JSON.parse(e.newValue);o.$uuid&&o&&o.$uuid!==a&&(o.type===c&&r?t.dispatch(s()):o.type===f?(t.dispatch(l(o.payload)),r=!0):n(o.type)&&(a=o.$uuid,t.dispatch(o),r=!0))}catch(t){}})}Object.defineProperty(e,"__esModule",{value:!0}),e.generateUuidForAction=i,e.createStorageListener=u;var a=0,c="&_GET_INIT_STATE",f="&_SEND_INIT_STATE",d={initiateWithState:!1,predicate:null,ignore:[]},p=function(){return{type:c}},s=function(){return{type:f}},l=function(t){return{type:"&_RECEIVE_INIT_STATE",payload:t}};e.withReduxStateSync=function(t){return function(e,r){return"&_RECEIVE_INIT_STATE"===r.type&&(e=r.payload),t(e,r)}},e.actionStorageMiddleware=function(t){var e=t.getState;return function(t){return function(r){if(r&&!r.$uuid){var n=i(r);a=n.$uuid;try{if(r.type===f)return e()&&(n.payload=e(),localStorage.setItem("LAST_ACTION",JSON.stringify(n))),t(r);localStorage.setItem("LAST_ACTION",JSON.stringify(n))}catch(t){console.error("Your browser doesn't support localStorage")}}return t(r)}}}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.reduxStateSync=e():t.reduxStateSync=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";function n(){return o()+o()+"-"+o()+"-"+o()+"-"+o()+"-"+o()+o()+o()}function o(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function i(t){var e=t;return e.$uuid=n(),e.$wuid=y,e}function u(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d,r=!1,n=function(){return!0};e.predicate&&"function"==typeof e.predicate?n=e.predicate:Array.isArray(e.ignore)&&(n=function(t){return e.ignore.indexOf(t)<0}),e.initiateWithState&&t.dispatch(p()),window.addEventListener("storage",function(e){try{var o=JSON.parse(e.newValue);if(o.$wuid===y)return;o.$uuid&&o&&o.$uuid!==a&&(o.type===c&&r?t.dispatch(s()):o.type===f?(t.dispatch(l(o.payload)),r=!0):n(o.type)&&(a=o.$uuid,t.dispatch(o),r=!0))}catch(t){}})}Object.defineProperty(e,"__esModule",{value:!0}),e.generateUuidForAction=i,e.createStorageListener=u;var a=0,c="&_GET_INIT_STATE",f="&_SEND_INIT_STATE",d={initiateWithState:!1,predicate:null,ignore:[]},p=function(){return{type:c}},s=function(){return{type:f}},l=function(t){return{type:"&_RECEIVE_INIT_STATE",payload:t}},y=n();e.withReduxStateSync=function(t){return function(e,r){return"&_RECEIVE_INIT_STATE"===r.type&&(e=r.payload),t(e,r)}},e.actionStorageMiddleware=function(t){var e=t.getState;return function(t){return function(r){if(r&&!r.$uuid){var n=i(r);a=n.$uuid;try{if(r.type===f)return e()&&(n.payload=e(),localStorage.setItem("LAST_ACTION",JSON.stringify(n))),t(r);localStorage.setItem("LAST_ACTION",JSON.stringify(n))}catch(t){console.error("Your browser doesn't support localStorage")}}return t(r)}}}}])}); | ||
//# sourceMappingURL=syncStorage.umd.min.js.map |
@@ -34,5 +34,9 @@ let lastUuid = 0; | ||
// generate current window unique id | ||
const _WINDOW_STATE_SYNC_ID = guid(); | ||
export function generateUuidForAction(action) { | ||
const stampedAction = action; | ||
stampedAction.$uuid = guid(); | ||
stampedAction.$wuid = _WINDOW_STATE_SYNC_ID; | ||
return stampedAction; | ||
@@ -87,2 +91,8 @@ } | ||
const stampedAction = JSON.parse(event.newValue); | ||
// ignore if this action is triggered by this window | ||
// IE bug https://stackoverflow.com/questions/18265556/why-does-internet-explorer-fire-the-window-storage-event-on-the-window-that-st | ||
if (stampedAction.$wuid === _WINDOW_STATE_SYNC_ID) { | ||
return; | ||
} | ||
// ignore other values that saved to localstorage. | ||
@@ -89,0 +99,0 @@ if (stampedAction.$uuid) { |
{ | ||
"name": "redux-state-sync", | ||
"version": "1.1.1", | ||
"version": "1.2.1", | ||
"description": "A middleware for redux to sync state in different tabs", | ||
@@ -5,0 +5,0 @@ "main": "dist/syncStorage.js", |
@@ -5,8 +5,9 @@ # Redux-State-Sync | ||
[![travis build](https://img.shields.io/travis/AOHUA/redux-state-sync.svg)](https://travis-ci.org/AOHUA/redux-state-sync) | ||
[![downloads](https://img.shields.io/npm/dm/redux-state-sync.svg)](https://www.npmjs.com/package/redux-state-sync) | ||
[<img src="https://img.shields.io/travis/AOHUA/redux-state-sync.svg">](https://travis-ci.org/AOHUA/redux-state-sync) | ||
[<img src="https://img.shields.io/npm/dm/redux-state-sync.svg">](https://www.npmjs.com/package/redux-state-sync) | ||
### How to install | ||
Simply install it with npm. | ||
Install with npm or yarn. | ||
@@ -16,3 +17,3 @@ ``` | ||
or | ||
or | ||
@@ -30,3 +31,3 @@ yarn add redux-state-sync | ||
``` | ||
```javascript | ||
import { actionStorageMiddleware, createStorageListener } from 'redux-state-sync'; | ||
@@ -57,3 +58,3 @@ | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -90,3 +91,3 @@ ignore: ['CHANGE_USERNAME', 'REPO_REQUEST'], | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -105,3 +106,3 @@ predicate: actionType => actionType !== 'GET_REPO', | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -113,3 +114,3 @@ initiateWithState: true, | ||
You also need to wrap your root reducer with 'withReduxStateSync' function. | ||
``` | ||
```javascript | ||
import { withReduxStateSync } from 'redux-state-sync' | ||
@@ -116,0 +117,0 @@ |
@@ -34,5 +34,9 @@ let lastUuid = 0; | ||
// generate current window unique id | ||
const _WINDOW_STATE_SYNC_ID = guid(); | ||
export function generateUuidForAction(action) { | ||
const stampedAction = action; | ||
stampedAction.$uuid = guid(); | ||
stampedAction.$wuid = _WINDOW_STATE_SYNC_ID; | ||
return stampedAction; | ||
@@ -87,2 +91,8 @@ } | ||
const stampedAction = JSON.parse(event.newValue); | ||
// ignore if this action is triggered by this window | ||
// IE bug https://stackoverflow.com/questions/18265556/why-does-internet-explorer-fire-the-window-storage-event-on-the-window-that-st | ||
if (stampedAction.$wuid === _WINDOW_STATE_SYNC_ID) { | ||
return; | ||
} | ||
// ignore other values that saved to localstorage. | ||
@@ -89,0 +99,0 @@ if (stampedAction.$uuid) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
534163
1002
120