1.0.0 • Published 3 years ago

@ngneat/storage v1.0.0

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

The simple storage implementation with support for Observable and Promise

MIT commitizen PRs styled with prettier All Contributors ngneat-lib spectator semantic-release

The 'storage' library is dedicated to support various implementation of storage which implements API similar to the 'localStorage.'. The biggest advantage is support for Observable and Promise. It's allow us to add support of the custom persistence manager within following libs: @ngneat/reactive-forms, @ngneat/forms-manager, @ngneat/cashew

Table of Contents

Installation

ng add @ngneat/storage

NPM

npm install @ngneat/storage --save-dev

Yarn

yarn add @ngneat/storage --dev

Usage

By default the library provides LocalStorageManager and SessionStorageManager. It's possible to store the form value into a custom storage. Just implement the PersistManager interface, and use it when calling the upsert function. Storage supports Promise and Observable

export class StateStoreManager<T> implements PersistManager<T> {
  setValue(key: string, data: T) {
     ...
  }
  getValue(key: string) {
    ...
  }
}

Library also export's helper methods and types:

###Types

  • MaybeAsync - Type that indicates that value might be Observable or Promise

###Class

  • StorageFacade - Accepts PersistManager implementation as parameter and implements get and update methods.
    • get Return value for the given key
    • update - Update storage under specific key using provided callback function.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

1.0.0

3 years ago