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 1.1.0 to 2.0.0

dist/index.d.ts

60

package.json
{
"name": "reduxed-chrome-storage",
"version": "1.1.0",
"description": "Redux interface to chrome.storage, the only way to get Redux working in event-driven (non-persistent) Chrome extensions",
"version": "2.0.0",
"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",
"license": "MIT",
"author": "Savr Goryaev",
"repository": "github:hindmost/reduxed-chrome-storage",

@@ -18,26 +19,35 @@ "bugs": "https://github.com/hindmost/reduxed-chrome-storage/issues",

],
"main": "lib/index.umd.js",
"module": "lib/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"unpkg": "dist/index.min.js",
"types": "dist/index.d.ts",
"files": [
"lib"
"dist"
],
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"lodash.isequal": "^4.5.0",
"lodash.mergewith": "^4.6.0"
"peerDependencies": {
"redux": "^4"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^6.0.0",
"lodash": "^4.17.20",
"mocha": "^8.2.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"reify": "^0.20.12",
"rollup": "^2.26.0",
"@rollup/plugin-buble": "^0.21.0",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"rollup-plugin-terser": "^7.0.0",
"sinon": "^9.2.0"
"chai": "^4",
"eslint": "^6",
"eslint-import-resolver-typescript": "^2",
"eslint-plugin-import": "^2",
"mocha": "^8",
"redux": "^4",
"redux-thunk": "^2",
"rollup": "^2",
"@rollup/plugin-buble": "^0.21",
"rollup-plugin-delete": "^2",
"rollup-plugin-license": "^2",
"rollup-plugin-terser": "^7",
"rollup-plugin-typescript2": "^0.29",
"sinon": "^9",
"ts-mocha": "^8",
"typescript": "^4",
"@types/chai": "^4",
"@types/mocha": "^8",
"@types/node": "^14",
"@types/sinon": "^9",
"@typescript-eslint/eslint-plugin": "^4",
"@typescript-eslint/parser": "^4"
},

@@ -48,8 +58,8 @@ "scripts": {

"dev": "rollup -c -w",
"lint": "eslint src",
"lint:test": "eslint test",
"lint": "eslint src --ext .ts",
"lint:test": "eslint test --ext .ts",
"pretest": "npm run lint:test",
"test": "mocha -r reify",
"test": "ts-mocha -p test/tsconfig.json test/*.ts",
"prepublishOnly": "npm run build"
}
}
# Reduxed Chrome Storage
Redux interface to [`chrome.storage`](https://developer.chrome.com/extensions/storage). The only way to get Redux working in [event-driven](https://developer.chrome.com/extensions/background_migration) (non-persistent) Chrome extensions (aside from full reproduction of the Redux code).
Redux interface to [`chrome.storage`](https://developer.chrome.com/extensions/storage). Unified way to use Redux in all modern browser extensions. The only way to get Redux working in [Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/) Chrome extensions (aside from full reproduction of the Redux code).
[Related article](https://levelup.gitconnected.com/using-redux-in-event-driven-chrome-extensions-problem-solution-30eed1207a42)
## Installation
With [NPM](https://www.npmjs.com/):
```

@@ -20,5 +19,2 @@ npm install reduxed-chrome-storage

```js
// Note: the usage is the SAME for ANY extension component
// (background or content script or popup - no matter)
import { createStore } from 'redux';

@@ -28,4 +24,13 @@ import storeCreatorFactory from 'reduxed-chrome-storage';

const storeCreator = storeCreatorFactory({ createStore });
storeCreator(reducer).then(store => {
const options = {
createStore: createStore,
namespace?: ...,
chromeNs?: ...,
browserNs?: ...,
storageArea?: ...,
storageKey?: ...,
bufferLife?: ...
};
const asyncStoreCreator = storeCreatorFactory(options);
asyncStoreCreator(reducer).then(store => {
const state = store.getState();

@@ -41,4 +46,4 @@ ...

async () => {
const storeCreator = storeCreatorFactory({ createStore });
const store = await storeCreator(reducer);
const asyncStoreCreator = storeCreatorFactory({ createStore });
const store = await asyncStoreCreator(reducer);
...

@@ -54,3 +59,3 @@ }

async () => {
const store = await storeCreatorFactory({ createStore }) (reducer);
const store = await storeCreatorFactory({ createStore })( reducer );
...

@@ -61,10 +66,54 @@ }

### Notes
## Options
`storeCreator` function returned by `storeCreatorFactory` is similar to the original Redux's `createStore` function except that the former runs in async way returning a promise instead of a new store (which is due to asynchronous nature of `chrome.storage` API). Although `storeCreator` has the same syntax as its Redux's counterpart, its 2nd parameter has a slightly different meaning. Unlike Redux, this library features state persistence through extension's activity periods (browser sessions in the case of persistent extension). With Reduxed Chrome Storage the current state is always persisted in `chrome.storage` by default. So there is no need to specify a previosly (somewhere) serialized state upon store creation/instantiation. However there may be a need to reset some parts (properties) of the state (e.g. user session variables) to their initial values upon store instantiation. And this is how the 2nd parameter is supposed to be used in Reduxed Chrome Storage: as initial values for some specific state properties. To be more specific, when a new store is created by `storeCreator`, first it tries to restore its last state from `chrome.storage`, then the result is merged with the 2nd parameter (if supplied).
### createStore
Type: `function`
If you declare your background script as non-persistent, you have to keep in mind that it must comply with requirements of [event-based model](https://developer.chrome.com/extensions/background_pages). In the context of usage of this library it means that `storeCreator`'s promise callback should not contain any extension event listener (e.g. `chrome.runtime.onStartup` etc). If `async/await` syntax is used, there should not be any event listener after first `await` occurrence. Furthermore, `storeCreatorFactory` should not be called inside any event listener (as it implicitly sets up `chrome.storage.onChanged` event listener).
The original Redux's `createStore` function. The only mandatory option.
### namespace
Type: `string`<br>
Default: `'chrome'`
A string to identify the APIs namespace to be used, either `'chrome'` or `'browser'`. If this and the next two options are missing, the chrome namespace is used by default.
### chromeNs
Type: `host object`
The chrome namespace within Manifest V2 extension. If this option is supplied, the previous one is ignored.
### browserNs
Type: `host object`
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.
### storageArea
Type: `string`<br>
Default: `'sync'`
The name of `chrome.storage` area to be used, either `'sync'` or `'local'`.
### storageKey
Type: `string`<br>
Default: `'reduxed'`
The key to be used for storing/tracking data in `chrome.storage`.
### bufferLife
Type: `number`<br>
Default: `100`
Lifetime of the bulk actions buffer (in ms).
## Notes
The usage is the _**same**_ for _**any**_ extension component (background or content script or popup - no matter).
`asyncStoreCreator` function returned by `storeCreatorFactory` is similar to the original Redux's `createStore` function except that unlike the latter `asyncStoreCreator` runs in async way returning a promise instead of a new store (which is due to asynchronous nature of `chrome.storage` API). `asyncStoreCreator` has the same syntax as its Redux's counterpart, though its 2nd parameter has a slightly different meaning. Unlike Redux, this library features state persistence through extension's activity periods (browser sessions in the case of persistent extension). With Reduxed Chrome Storage the current state is always persisted in `chrome.storage` by default. So there is no need to specify a previosly (somewhere) serialized state upon store creation/instantiation. However there may be a need to reset some parts (properties) of the state (e.g. user session variables) to their initial values upon store instantiation. And this is how the 2nd parameter is supposed to be used in Reduxed Chrome Storage: as initial values for some specific state properties. To be more specific, when a new store is created by `asyncStoreCreator`, first it tries to restore its last state from `chrome.storage`, then the result is merged with the 2nd parameter (if supplied).
If you're developing a Manifest V3 Chrome extension or a Manifest V2 extension with non-persistent background script, you have to keep in mind that your background script must comply with requirements of [event-based model](https://developer.chrome.com/extensions/background_pages). In the context of usage of this library it means that `asyncStoreCreator`'s promise callback should not contain any extension event listener (e.g. `chrome.runtime.onStartup` etc). If `async/await` syntax is used, there should not be any event listener after first `await` occurrence. Furthermore, `storeCreatorFactory` should not be called inside any event listener (as it implicitly sets up `chrome.storage.onChanged` event listener).
## License
Licensed under the MIT license.

Sorry, the diff of this file is not supported yet

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