Socket
Book a DemoInstallSign in
Socket

@singletn/indexeddb

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@singletn/indexeddb

## Persist your data

latest
Source
npmnpm
Version
0.0.18
Version published
Maintainers
1
Created
Source

@singletn/indexeddb  npm version

Persist your data

If you'd like to have a persistent state in indexeddb, you can do so by having your state extend IndexedDBSingletn.

The implementation is the same as using the SingletnState from @singletn/core.

import { IndexedDBSingletn } from '@singletn/indexeddb'

interface UserState {
  name: string
  email: string
  phoneNumber: string
}

export class User extends IndexedDBSingletn<UserState> {
  state = {
    name: '',
    email: '',
    phoneNumber: '',
  }

  public setUser = (user: UserState) => this.setState(user)

  public setName = (name) => this.setState({ name })

  public setEmail = (email) => this.setState({ email })

  // ...
}

Cleanup remark

Anytime that you use clearSingletns from @singletn/core, the databases created will be all cleared, and the data will, obviously, no longer persist.

If, however, you'd like to manually trigger a deletion of the database for any given singletn, you can call the clearDB method:

export class User extends IndexedDBSingletn<UserState> {
  // ...

  public cleanup = () => this.clearDB()

  // ...
}

Other ways to store your state

singletn also allows you to use different base states to store your data in other ways. Read more about it in the subprojects:

FAQs

Package last updated on 15 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.