Socket
Socket
Sign inDemoInstall

reduxed-chrome-storage

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduxed-chrome-storage - npm Package Compare versions

Comparing version 2.0.5 to 2.2.0

24

dist/index.d.ts

@@ -5,2 +5,3 @@ import { StoreCreator, StoreEnhancer, Reducer } from 'redux';

export { ChromeNamespace, BrowserNamespace } from './types/apis';
export declare type ChangeListener = (store: ExtendedStore, oldState?: any) => void;
/**

@@ -15,17 +16,25 @@ * ReduxedChromeStorage creator factory.

* @param obj.createStore the original Redux's createStore function.
* The only mandatory parameter/property
* The only mandatory property/option
* @param obj.namespace string to identify the APIs namespace to be used,
* either 'chrome' or 'browser'.
* If this and the next two properties are missing,
* If this and the next two options are missing,
* the chrome namespace is used by default
* @param obj.chromeNs the chrome namespace within Manifest V2 extension.
* If this property is supplied, the previous one is ignored
* If this option is supplied, the previous one is ignored
* @param obj.browserNs the browser namespace within Firefox extension,
* or the chrome namespace within Manifest V3 chrome extension.
* You may pass the chrome namespace within Manifest V3 to make this library
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this property is supplied, the previous two are ignored
* If this option is supplied, the previous two are ignored
* @param obj.changeListener a function to be called whenever the state changes,
* receives two parameters:
* a one-time store-container of the current state and the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is to only be used for holding the arguments to be passed to
* the original createStore upon a one-time store creation
* @param obj.storageArea the name of chrome.storage area to be used,
* defaults to 'sync'
* @param obj.storageKey the key to be used for storing/tracking data
* @param obj.storageKey key under which the state will be stored/tracked
* in chrome.storage, defaults to 'reduxed'

@@ -36,3 +45,3 @@ * @param obj.bufferLife lifetime of the bulk actions buffer (in ms),

*/
export default function reduxedStorageCreatorFactory({ createStore, namespace, chromeNs, browserNs, storageArea, storageKey, bufferLife }: {
export default function reduxedStorageCreatorFactory({ createStore, namespace, chromeNs, browserNs, changeListener, storageArea, storageKey, bufferLife }: {
createStore: StoreCreator;

@@ -42,2 +51,3 @@ namespace?: string;

browserNs?: BrowserNamespace;
changeListener?: ChangeListener;
storageArea?: string;

@@ -44,0 +54,0 @@ storageKey?: string;

/**
* @license
* ReduxedChromeStorage v2.0.5
* ReduxedChromeStorage v2.2.0
* https://github.com/hindmost/reduxed-chrome-storage

@@ -51,3 +51,4 @@ * Copyright (c) Savr Goryaev aka hindmost

this.buffLife = bufferLife ? Math.min(Math.max(bufferLife, 0), 2000) : 100;
this.state = initialState;
this.state0 = initialState;
this.state = null;
this.buffStore = null;

@@ -65,7 +66,5 @@ this.lastState = null;

});
const initialState = this.state;
this.state = null;
const defaultState = this._createStore().getState();
// subscribe for changes in chrome.storage
this.storage.subscribe(data => {
this.storage.subscribe((data, oldData) => {
if (isEqual(data, this.state))

@@ -75,3 +74,3 @@ return;

for (const fn of this.listeners) {
fn();
fn(oldData);
}

@@ -86,4 +85,4 @@ });

mergeOrReplace(defaultState, storedState) : defaultState;
if (initialState) {
state = mergeOrReplace(state, initialState);
if (this.state0) {
state = mergeOrReplace(state, this.state0);
}

@@ -98,2 +97,12 @@ this._setState(state);

}
initFrom(state) {
this._setState(state);
this.inited = true;
return this;
}
uninit() {
return new Promise(resolve => {
resolve(this);
});
}
_createStore(initialState) {

@@ -211,3 +220,3 @@ try {

return;
const { newValue } = changes[this.key];
const { newValue, oldValue } = changes[this.key];
if (!newValue)

@@ -217,3 +226,3 @@ return;

for (const fn of this.listeners) {
fn(newValue, this.areaName);
fn(newValue, oldValue);
}

@@ -281,17 +290,25 @@ });

* @param obj.createStore the original Redux's createStore function.
* The only mandatory parameter/property
* The only mandatory property/option
* @param obj.namespace string to identify the APIs namespace to be used,
* either 'chrome' or 'browser'.
* If this and the next two properties are missing,
* If this and the next two options are missing,
* the chrome namespace is used by default
* @param obj.chromeNs the chrome namespace within Manifest V2 extension.
* If this property is supplied, the previous one is ignored
* If this option is supplied, the previous one is ignored
* @param obj.browserNs the browser namespace within Firefox extension,
* or the chrome namespace within Manifest V3 chrome extension.
* You may pass the chrome namespace within Manifest V3 to make this library
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this property is supplied, the previous two are ignored
* If this option is supplied, the previous two are ignored
* @param obj.changeListener a function to be called whenever the state changes,
* receives two parameters:
* a one-time store-container of the current state and the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is to only be used for holding the arguments to be passed to
* the original createStore upon a one-time store creation
* @param obj.storageArea the name of chrome.storage area to be used,
* defaults to 'sync'
* @param obj.storageKey the key to be used for storing/tracking data
* @param obj.storageKey key under which the state will be stored/tracked
* in chrome.storage, defaults to 'reduxed'

@@ -302,5 +319,5 @@ * @param obj.bufferLife lifetime of the bulk actions buffer (in ms),

*/
function reduxedStorageCreatorFactory({ createStore, namespace, chromeNs, browserNs, storageArea, storageKey, bufferLife }) {
function reduxedStorageCreatorFactory({ createStore, namespace, chromeNs, browserNs, changeListener, storageArea, storageKey, bufferLife }) {
if (typeof createStore !== 'function')
throw new Error(`Missing 'createStore' parameter/property`);
throw new Error(`Missing 'createStore' property/option`);
const storage = browserNs || namespace === Namespace.browser ?

@@ -327,3 +344,8 @@ new WrappedBrowserStorage({

});
return store.init();
if (typeof changeListener !== 'function')
return store.init();
storage.subscribe((data, oldData) => {
changeListener(store.initFrom(data), oldData);
});
return store.uninit();
}

@@ -330,0 +352,0 @@ return asyncStoreCreator;

/**
* @license
* ReduxedChromeStorage v2.0.5
* ReduxedChromeStorage v2.2.0
* https://github.com/hindmost/reduxed-chrome-storage

@@ -65,3 +65,4 @@ * Copyright (c) Savr Goryaev aka hindmost

this.buffLife = bufferLife ? Math.min(Math.max(bufferLife, 0), 2000) : 100;
this.state = initialState;
this.state0 = initialState;
this.state = null;
this.buffStore = null;

@@ -81,7 +82,5 @@ this.lastState = null;

}); }
var initialState = this.state;
this.state = null;
var defaultState = this._createStore().getState();
// subscribe for changes in chrome.storage
this.storage.subscribe(function (data) {
this.storage.subscribe(function (data, oldData) {
if (isEqual(data, this$1.state))

@@ -93,3 +92,3 @@ { return; }

fn();
fn(oldData);
}

@@ -104,4 +103,4 @@ });

mergeOrReplace(defaultState, storedState) : defaultState;
if (initialState) {
state = mergeOrReplace(state, initialState);
if (this$1.state0) {
state = mergeOrReplace(state, this$1.state0);
}

@@ -116,2 +115,14 @@ this$1._setState(state);

};
ReduxedStorage.prototype.initFrom = function initFrom (state) {
this._setState(state);
this.inited = true;
return this;
};
ReduxedStorage.prototype.uninit = function uninit () {
var this$1 = this;
return new Promise(function (resolve) {
resolve(this$1);
});
};
ReduxedStorage.prototype._createStore = function _createStore (initialState) {

@@ -240,2 +251,3 @@ try {

var newValue = ref.newValue;
var oldValue = ref.oldValue;
if (!newValue)

@@ -247,3 +259,3 @@ { return; }

fn(newValue, this$1.areaName);
fn(newValue, oldValue);
}

@@ -340,17 +352,25 @@ });

* @param obj.createStore the original Redux's createStore function.
* The only mandatory parameter/property
* The only mandatory property/option
* @param obj.namespace string to identify the APIs namespace to be used,
* either 'chrome' or 'browser'.
* If this and the next two properties are missing,
* If this and the next two options are missing,
* the chrome namespace is used by default
* @param obj.chromeNs the chrome namespace within Manifest V2 extension.
* If this property is supplied, the previous one is ignored
* If this option is supplied, the previous one is ignored
* @param obj.browserNs the browser namespace within Firefox extension,
* or the chrome namespace within Manifest V3 chrome extension.
* You may pass the chrome namespace within Manifest V3 to make this library
* One may pass the chrome namespace within Manifest V3 to make this library
* use Promise-based APIs under the hood.
* If this property is supplied, the previous two are ignored
* If this option is supplied, the previous two are ignored
* @param obj.changeListener a function to be called whenever the state changes,
* receives two parameters:
* a one-time store-container of the current state and the previous state.
* This option only makes sense in Manifest V3 service workers
* or event-driven background scripts.
* If this option is supplied, the async store creator returned by the factory
* is to only be used for holding the arguments to be passed to
* the original createStore upon a one-time store creation
* @param obj.storageArea the name of chrome.storage area to be used,
* defaults to 'sync'
* @param obj.storageKey the key to be used for storing/tracking data
* @param obj.storageKey key under which the state will be stored/tracked
* in chrome.storage, defaults to 'reduxed'

@@ -366,2 +386,3 @@ * @param obj.bufferLife lifetime of the bulk actions buffer (in ms),

var browserNs = ref.browserNs;
var changeListener = ref.changeListener;
var storageArea = ref.storageArea;

@@ -372,3 +393,3 @@ var storageKey = ref.storageKey;

if (typeof createStore !== 'function')
{ throw new Error("Missing 'createStore' parameter/property"); }
{ throw new Error("Missing 'createStore' property/option"); }
var storage = browserNs || namespace === Namespace.browser ?

@@ -395,3 +416,8 @@ new WrappedBrowserStorage({

});
return store.init();
if (typeof changeListener !== 'function')
{ return store.init(); }
storage.subscribe(function (data, oldData) {
changeListener(store.initFrom(data), oldData);
});
return store.uninit();
}

@@ -398,0 +424,0 @@ return asyncStoreCreator;

/**
* @license
* ReduxedChromeStorage v2.0.5
* ReduxedChromeStorage v2.2.0
* https://github.com/hindmost/reduxed-chrome-storage

@@ -11,2 +11,2 @@ * Copyright (c) Savr Goryaev aka hindmost

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).reduxedChromeStorage=e()}(this,(function(){"use strict";function t(e){return null==e||"object"!=typeof e?e:Array.isArray(e)?e.map((function(e){return t(e)})):Object.keys(e).reduce((function(r,n){return r[n]=t(e[n]),r}),{})}function e(t,r){if(t===r)return!0;if(null==t||"object"!=typeof t||null==r||"object"!=typeof r)return!1;var n=Object.keys(t),i=Object.keys(r);if(n.length!==i.length)return!1;for(var o=0,s=n;s.length>o;o+=1){var a=s[o];if(-1>=i.indexOf(a)||!e(t[a],r[a]))return!1}return!0}function r(e,n){return Array.isArray(n)?t(n):"object"!=typeof e||Array.isArray(e)||"object"!=typeof n?void 0!==n?n:e:Object.keys(e).concat(Object.keys(n).filter((function(t){return!e[t]}))).reduce((function(t,i){return t[i]=r(e[i],n[i]),t}),{})}var n,i=function(t){var e=t.reducer,r=t.storage,n=t.bufferLife,i=t.initialState,o=t.enhancer;this.createStore=t.createStore,this.storage=r,this.reducer=e,this.enhancer=o,this.buffLife=n?Math.min(Math.max(n,0),2e3):100,this.state=i,this.buffStore=null,this.lastState=null,this.listeners=[],this.inited=!1,this.dispatch=this.dispatch.bind(this),this.subscribe=this.subscribe.bind(this)};i.prototype.init=function(){var t=this;if(this.inited)return new Promise((function(e){e(t)}));var n=this.state;this.state=null;var i=this._createStore().getState();return this.storage.subscribe((function(r){if(!e(r,t.state)){t._setState(r);for(var n=0,i=t.listeners;i.length>n;n+=1){(0,i[n])()}}})),this.inited=!0,new Promise((function(o){t.storage.load((function(s){var a=s?r(i,s):i;n&&(a=r(a,n)),t._setState(a),e(a,s)||t._send2Storage(a),o(t)}))}))},i.prototype._createStore=function(t){try{return this.createStore(this.reducer,t,this.enhancer)}catch(t){throw Error("createStore() call failed")}},i.prototype._send2Storage=function(t){try{this.storage.save(t)}catch(t){throw Error("Browser storage limit exceeded")}},i.prototype._setState=function(e){e&&(this.state=t(e))},i.prototype.getState=function(){return this.state},i.prototype.subscribe=function(t){var e=this;return"function"==typeof t&&this.listeners.push(t),function(){"function"==typeof t&&(e.listeners=e.listeners.filter((function(e){return e!==t})))}},i.prototype.dispatch=function(t){var r=this;this.buffStore||(this.buffStore=this._createStore(this.state),this.lastState=this.buffStore.getState(),setTimeout((function(){r.buffStore=null}),this.buffLife));var n=this.buffStore,i=n.subscribe((function(){var t=r.buffStore||n,o=t&&t.getState();e(o,r.lastState)||(r._send2Storage(o),r.lastState=o,i(),n=null)}));return n.dispatch(t)},i.prototype.replaceReducer=function(t){return"function"==typeof t&&(this.reducer=t),this},i.prototype[Symbol.observable]=function(){var t,e=this.getState,r=this.subscribe;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new TypeError("Expected the observer to be an object.");function n(){t.next&&t.next(e())}return n(),{unsubscribe:r(n)}}})[Symbol.observable]=function(){return this},t},function(t){t.local="local",t.sync="sync"}(n||(n={}));var o=function(t){var e=t.area,r=t.key;this.ns=t.namespace,this.areaName=e===n.sync?n.sync:n.local,this.key=r||"reduxed",this.listeners=[]};o.prototype.init=function(){var t=this;this.ns.storage.onChanged.addListener((function(e,r){if(r===t.areaName&&t.key in e){var n=e[t.key].newValue;if(n)for(var i=0,o=t.listeners;o.length>i;i+=1){(0,o[i])(n,t.areaName)}}}))},o.prototype.subscribe=function(t){"function"==typeof t&&this.listeners.push(t)};var s,a=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key,(function(r){t(!e.ns.runtime.lastError&&r&&r[e.key])}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set(((e={})[this.key]=t,e),(function(){if(r.ns.runtime.lastError)throw Error()}))},e}(o),c=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key).then((function(r){t(!e.ns.runtime.lastError&&r&&r[e.key])}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set((e={},e[this.key]=t,e)).then((function(){if(r.ns.runtime.lastError)throw Error()}))},e}(o);return function(t){t.chrome="chrome",t.browser="browser"}(s||(s={})),function(t){var e=t.createStore,r=t.namespace,n=t.chromeNs,o=t.browserNs,u=t.storageArea,f=t.storageKey,h=t.bufferLife;if("function"!=typeof e)throw Error("Missing 'createStore' parameter/property");var p=o||r===s.browser?new c({namespace:o||browser,area:u,key:f}):new a({namespace:n||chrome,area:u,key:f});return p.init(),function(t,r,n){if("function"!=typeof t)throw Error("Missing 'reducer' parameter");if("function"==typeof r&&"function"==typeof n)throw Error("Multiple 'enhancer' parameters unallowed");return"function"==typeof r&&void 0===n&&(n=r,r=void 0),new i({createStore:e,storage:p,bufferLife:h,reducer:t,initialState:r,enhancer:n}).init()}}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).reduxedChromeStorage=e()}(this,(function(){"use strict";function t(e){return null==e||"object"!=typeof e?e:Array.isArray(e)?e.map((function(e){return t(e)})):Object.keys(e).reduce((function(r,n){return r[n]=t(e[n]),r}),{})}function e(t,r){if(t===r)return!0;if(null==t||"object"!=typeof t||null==r||"object"!=typeof r)return!1;var n=Object.keys(t),i=Object.keys(r);if(n.length!==i.length)return!1;for(var o=0,s=n;s.length>o;o+=1){var a=s[o];if(-1>=i.indexOf(a)||!e(t[a],r[a]))return!1}return!0}function r(e,n){return Array.isArray(n)?t(n):"object"!=typeof e||Array.isArray(e)||"object"!=typeof n?void 0!==n?n:e:Object.keys(e).concat(Object.keys(n).filter((function(t){return!e[t]}))).reduce((function(t,i){return t[i]=r(e[i],n[i]),t}),{})}var n,i=function(t){var e=t.reducer,r=t.storage,n=t.bufferLife,i=t.initialState,o=t.enhancer;this.createStore=t.createStore,this.storage=r,this.reducer=e,this.enhancer=o,this.buffLife=n?Math.min(Math.max(n,0),2e3):100,this.state0=i,this.state=null,this.buffStore=null,this.lastState=null,this.listeners=[],this.inited=!1,this.dispatch=this.dispatch.bind(this),this.subscribe=this.subscribe.bind(this)};i.prototype.init=function(){var t=this;if(this.inited)return new Promise((function(e){e(t)}));var n=this._createStore().getState();return this.storage.subscribe((function(r,n){if(!e(r,t.state)){t._setState(r);for(var i=0,o=t.listeners;o.length>i;i+=1){(0,o[i])(n)}}})),this.inited=!0,new Promise((function(i){t.storage.load((function(o){var s=o?r(n,o):n;t.state0&&(s=r(s,t.state0)),t._setState(s),e(s,o)||t._send2Storage(s),i(t)}))}))},i.prototype.initFrom=function(t){return this._setState(t),this.inited=!0,this},i.prototype.uninit=function(){var t=this;return new Promise((function(e){e(t)}))},i.prototype._createStore=function(t){try{return this.createStore(this.reducer,t,this.enhancer)}catch(t){throw Error("createStore() call failed")}},i.prototype._send2Storage=function(t){try{this.storage.save(t)}catch(t){throw Error("Browser storage limit exceeded")}},i.prototype._setState=function(e){e&&(this.state=t(e))},i.prototype.getState=function(){return this.state},i.prototype.subscribe=function(t){var e=this;return"function"==typeof t&&this.listeners.push(t),function(){"function"==typeof t&&(e.listeners=e.listeners.filter((function(e){return e!==t})))}},i.prototype.dispatch=function(t){var r=this;this.buffStore||(this.buffStore=this._createStore(this.state),this.lastState=this.buffStore.getState(),setTimeout((function(){r.buffStore=null}),this.buffLife));var n=this.buffStore,i=n.subscribe((function(){var t=r.buffStore||n,o=t&&t.getState();e(o,r.lastState)||(r._send2Storage(o),r.lastState=o,i(),n=null)}));return n.dispatch(t)},i.prototype.replaceReducer=function(t){return"function"==typeof t&&(this.reducer=t),this},i.prototype[Symbol.observable]=function(){var t,e=this.getState,r=this.subscribe;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new TypeError("Expected the observer to be an object.");function n(){t.next&&t.next(e())}return n(),{unsubscribe:r(n)}}})[Symbol.observable]=function(){return this},t},function(t){t.local="local",t.sync="sync"}(n||(n={}));var o=function(t){var e=t.area,r=t.key;this.ns=t.namespace,this.areaName=e===n.sync?n.sync:n.local,this.key=r||"reduxed",this.listeners=[]};o.prototype.init=function(){var t=this;this.ns.storage.onChanged.addListener((function(e,r){if(r===t.areaName&&t.key in e){var n=e[t.key],i=n.newValue,o=n.oldValue;if(i)for(var s=0,a=t.listeners;a.length>s;s+=1){(0,a[s])(i,o)}}}))},o.prototype.subscribe=function(t){"function"==typeof t&&this.listeners.push(t)};var s,a=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key,(function(r){t(!e.ns.runtime.lastError&&r&&r[e.key])}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set(((e={})[this.key]=t,e),(function(){if(r.ns.runtime.lastError)throw Error()}))},e}(o),c=function(t){function e(e){t.call(this,{namespace:e.namespace,area:e.area,key:e.key}),this.areaApi=this.ns.storage[this.areaName]}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.load=function(t){var e=this;"function"==typeof t&&this.areaApi.get(this.key).then((function(r){t(!e.ns.runtime.lastError&&r&&r[e.key])}))},e.prototype.save=function(t){var e,r=this;this.areaApi.set((e={},e[this.key]=t,e)).then((function(){if(r.ns.runtime.lastError)throw Error()}))},e}(o);return function(t){t.chrome="chrome",t.browser="browser"}(s||(s={})),function(t){var e=t.createStore,r=t.namespace,n=t.chromeNs,o=t.browserNs,u=t.changeListener,f=t.storageArea,h=t.storageKey,p=t.bufferLife;if("function"!=typeof e)throw Error("Missing 'createStore' property/option");var y=o||r===s.browser?new c({namespace:o||browser,area:f,key:h}):new a({namespace:n||chrome,area:f,key:h});return y.init(),function(t,r,n){if("function"!=typeof t)throw Error("Missing 'reducer' parameter");if("function"==typeof r&&"function"==typeof n)throw Error("Multiple 'enhancer' parameters unallowed");"function"==typeof r&&void 0===n&&(n=r,r=void 0);var o=new i({createStore:e,storage:y,bufferLife:p,reducer:t,initialState:r,enhancer:n});return"function"!=typeof u?o.init():(y.subscribe((function(t,e){u(o.initFrom(t),e)})),o.uninit())}}}));
{
"name": "reduxed-chrome-storage",
"version": "2.0.5",
"description": "Redux interface to chrome.storage. Unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions",
"version": "2.2.0",
"description": "Redux-compatible interface to chrome.storage. Unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions",
"license": "MIT",

@@ -6,0 +6,0 @@ "author": "Savr Goryaev",

@@ -62,2 +62,26 @@ # Reduxed Chrome Storage

### State change listening (special case - only makes sense in Manifest V3 service workers):
```js
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducer from './reducer';
const changeListener = (store, oldState) => {
const currentState = store.getState();
...
};
const options = {
createStore: createStore,
changeListener: changeListener,
namespace?: ...,
chromeNs?: ...,
browserNs?: ...,
storageArea?: ...,
storageKey?: ...,
bufferLife?: ...
};
storeCreatorFactory(options)(reducer);
```
## Options

@@ -77,3 +101,3 @@

### chromeNs
Type: `host object`
Type: `host object` (`ChromeNamespace` in Typescript definition)

@@ -83,6 +107,16 @@ The chrome namespace within Manifest V2 extension. If this option is supplied, the previous one is ignored.

### browserNs
Type: `host object`
Type: `host object` (`BrowserNamespace` in Typescript definition)
The browser namespace within Firefox extension, or the chrome namespace within Manifest V3 chrome extension. You may pass the chrome namespace within Manifest V3 to make this library use Promise-based APIs under the hood. If this option is supplied, the previous two are ignored.
### changeListener
Type: `function` (`ChangeListener` in Typescript definition)<br>
A function to be called whenever the state changes, receives two parameters:
1. one-time store - container of the current state;
2. the previous state.
This option only makes sense in Manifest V3 service workers or event-driven background scripts. If this option is supplied, the async store creator returned by the factory is to only be used for holding the arguments to be passed to the original `createStore` upon a one-time store creation.
### storageArea

@@ -98,3 +132,3 @@ Type: `string`<br>

The key to be used for storing/tracking data in `chrome.storage`.
Key under which the state will be stored/tracked in `chrome.storage`.

@@ -101,0 +135,0 @@ ### bufferLife

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc