UNPKG

@restate/core

Version:

_Restate_ is a predictable, easy to use, easy to integrate, typesafe state container for [React](https://reactjs.org/).

31 lines (30 loc) 681 B
import { setAutoFreeze, enablePatches } from "immer"; import { BehaviorSubject } from "rxjs"; import { RestateStore } from "./rx-store"; enablePatches(); const RESTATE_STORE_DEFAULT_OPTIONS = { freeze: true, storeName: "STORE", dev: true }; function createStore({ state, middleware = [], options = RESTATE_STORE_DEFAULT_OPTIONS, trace }) { const opts = { ...RESTATE_STORE_DEFAULT_OPTIONS, ...options }; setAutoFreeze(opts.freeze); const initialStatePackage = { state, trace }; const state$ = new BehaviorSubject(initialStatePackage); return RestateStore.of(state$, middleware, opts); } export { RESTATE_STORE_DEFAULT_OPTIONS, createStore };