Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@effector-storage/idb-keyval

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effector-storage/idb-keyval

Module for Effector to sync stores with IndexedDB

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105
increased by34.62%
Maintainers
0
Weekly downloads
 
Created
Source

IndexedDB adapter

bundlejs

Adapter to persist store in IndexedDB, using idb-keyval library.

Install

Depending on your package manager

# using `pnpm` ↓
$ pnpm add effector-storage @effector-storage/idb-keyval

# using `yarn` ↓
$ yarn add effector-storage @effector-storage/idb-keyval

# using `npm` ↓
$ npm install --save effector-storage @effector-storage/idb-keyval

Usage

Import persist function from '@effector-storage/idb-keyval' module, and it will just work:

import { persist } from '@effector-storage/idb-keyval'

// persist store `$counter` with key 'counter'
persist({ store: $counter, key: 'counter' })

// if your storage has a name, you can omit `key` field
persist({ store: $counter })

⚠️ Note, that IndexedDB is asynchronous.

Two (or more) different stores, persisted with the same key, will be synchronized (synchronously!), even if not connected with each other directly — each store will receive updates from another one.

Formulae

import { persist } from '@effector-storage/idb-keyval'
  • persist({ store, ...options }): Subscription
  • persist({ source, target, ...options }): Subscription

Options

  • ... all the common options from effector-storage's persist function.
  • timeout?: (number): Timeout in milliseconds, which will be used to throttle and batch updates. Default = undefined (meaning updates will be saved immediately)
  • dbName?: (string): IndexedDB database name. Default = undefined (in that case default idb-keyval database will be used — 'keyval-store')
  • storeName?: (string): IndexedDB store name. Default = undefined (in that case default idb-keyval store will be used — 'keyval')
  • keyvalStore?: (UseStore): Custom idb-keyval store. Default = undefined (in that case default idb-keyval store will be used)

Adapter

import { adapter } from '@effector-storage/idb-keyval'
  • adapter(options?): StorageAdapter

Options

  • timeout?: (number): Timeout in milliseconds, which will be used to throttle and batch updates. Default = undefined (meaning updates will be saved immediately)
  • dbName?: (string): IndexedDB database name. Default = undefined (in that case default idb-keyval database will be used — 'keyval-store')
  • storeName?: (string): IndexedDB store name. Default = undefined (in that case default idb-keyval store will be used — 'keyval')
  • keyvalStore?: (UseStore): Custom idb-keyval store. Default = undefined (in that case default idb-keyval store will be used)

Gotchas

Although you can specify custom name for IndexedDB database, and custom name for IndexedDB store, I wouldn't recommend that. Please, read this document from idb-keyval library.

FAQ

How do I use custom serialization / deserialization?

You don't need to! IndexedDB can store any structured-clonable data.

Keywords

FAQs

Package last updated on 08 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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