Skip to content
Alexandre Moreau-Lemay edited this page Aug 20, 2022 · 1 revision

What is fresh-store?

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.

How does it work?

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.

What are some of its limitations?

  1. 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.

  1. Browser support:

In order to achieve minimum dependencies, fresh-store uses only native APIs, such as crypto.randomUUID and structuredClone. Because these are relatively new, not all versions of browser support them. The package will inject a polyfill from core-js for structuredClone if the browser doesn't support it.

Clone this wiki locally