-
Notifications
You must be signed in to change notification settings - Fork 0
Home
fresh-store is, despite its name, a framework agnostic multi-stores solution. It was originally developed for the fresh framework as a way to share state between islands with minimal external dependencies.
Once transpiled and minified, it adds about 2kb to the bundle.
It creates a stack of stores on the window element. Each store is associated a key, or pointer which can be used to access the store. The stores follow an observer pattern, where each store is a subject to which one or many observers can be attached.
- Values have to be serializable:
The store saves the state as a dereferenced value by deep cloning the passed-in value. Because of this, values passed-in must be serializable. That means that a class instance cannot be passed in as the state.
- Browser support:
In order to achieve minimum dependencies, fresh-store uses only native APIs, such as
crypto.randomUUIDandstructuredClone. Because these are relatively new, not all versions of browser support them. The package will inject a polyfill from core-js forstructuredCloneif the browser doesn't support it.