Search…
Store
Simple store that can be hooked into React.
Source code is hosted on GitHub
yarn
npm
yarn add @corets/store
npm install --save @corets/store
Seamless React integration is shipped in a separate package:
There is a version of this package that syncs directly to the localStorage:

createStore()

Creates a new instance of observable store:
import { createStore } from "@corets/store"
const store = createStore({ some: "data" })
Create a new instance without the factory function:
import { Store } from "@corets/store"
const store = new Store({ some: "data" })
Create a new instance with a custom differ:
import { createStore } from "@corets/store"
const differ = (oldValue, newValue) => true
const store = createStore({ some: "data" }, { differ })

Store.get()

Retrieve everything from the store:
store.get()

Store.set()

Replace everything in the store:
store.set({ foo: "bar" })

Store.put()

Update store by merging new and old state:
store.put({ some: "data" })

Store.listen()

Listen to changes:
store.listen((value) => console.log(value))
Listen to changes with a custom differ:
const differ = (oldValue, newValue) => true
store.listen((value) => console.log(value), { differ })
Listen to a subset of data, using a custom mapper:
const mapper = {value} => ({ })
store.listen((value) => console.log(value), { mapper })

Store.use()

Convenience method for people used to React's useState syntax:
import { createStore } from "@corets/store"
const [store, setStore] = createStore({ foo: "bar" }).use()
Copy link
On this page
createStore()
Store.get()
Store.set()
Store.put()
Store.listen()
Store.use()