0.0.17 • Published 1 year ago

@singletn/indexeddb v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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:

0.0.17

1 year ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.9

2 years ago

0.0.16

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago