0.0.17 • Published 3 months ago

@singletn/indexeddb v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months 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

3 months ago

0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

9 months ago

0.0.13

8 months ago

0.0.14

8 months ago

0.0.15

7 months ago

0.0.9

10 months ago

0.0.16

7 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago