0.2.7 • Published 2 years ago

@containrz/container-indexeddb v0.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@containrz/container-indexeddb

Persist your data

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

The implementation is the same as using the Container from @containrz/core.

import { IndexedDBContainer } from '@containrz/container-indexeddb'

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

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

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

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

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

  // ...
}

Cleanup remark

Anytime that you use clearContainers from @containrz/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 container, you can call the clearDB method:

export class UserContainer extends IndexedDBContainer<User> {
  // ...

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

  // ...
}

Other ways to store your state

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

0.2.7

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago