@bytesoftio/store
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@bytesoftio/store

Installation

yarn add @bytesoftio/store or npm install @bytesoftio/store

Table of contents

Description

Similar to the @bytesoftio/value package, except this one is optimized for use with objects. It comes with differs, mergers and can be used with a custom mapper / connector. Thanks to the @bytesoftio/use-store package, this library allows you to write stores that can be used in any environment as well as inside React through hooks.

createStore

Creates a new instance of ObservableStore .

import { createStore } from "@bytesoftio/store"

// create a new store from initial state
const store = createStore({some: "data"})

ObservableStore

A very simple observable like object.

import { createStore } from "@bytesoftio/store"

const store = createStore({firstName: "John", lastName: "Doe"})

// get the underlying store value, read only
store.get()

// update all of the store data
store.set({firstName: "Steve", lastName: "Jobs"})

// update some of the store data
store.add({lastName: "Wozniak"})

// reset store back to initial state {firstName: "John", lastName: "Doe"}
store.reset()

// reset store state and change its initial value
store.reset({firstName: "James", lastName: "Bond"})

// listen to state changes outside
store.listen(state => console.log(state))

Usage in React

To learn how to use this package inside React, please refer to the @bytesoftio/use-store package.

Readme

Keywords

none

Package Sidebar

Install

npm i @bytesoftio/store

Weekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

10.9 kB

Total Files

20

Last publish

Collaborators

  • maximkott