ilokesto

Store

@ilokesto/store is a small TypeScript state container for one application-owned value. It gives you a Store<T> class, synchronous reads with getState(), replacement updates with setState(), change listeners with subscribe(), and an explicit middleware pipeline.

Use it when you want a tiny state primitive that is independent of React, Vue, Svelte, Angular, or any other UI runtime. The package does not render UI, persist data, fetch from networks, or merge nested objects for you.

Install

npm install @ilokesto/store

What it gives you

import { Store } from "@ilokesto/store";

type CounterState = { count: number };

const counterStore = new Store<CounterState>({ count: 0 });

const unsubscribe = counterStore.subscribe(() => {
  console.log(counterStore.getState().count);
});

counterStore.setState((prev) => ({ count: prev.count + 1 }));
unsubscribe();

setState() replaces the stored value. If the resolved next value is Object.is-equal to the previous value, the store keeps the old value and does not notify listeners.

When to use it

Choose @ilokesto/store for small shared state, domain state outside a component tree, framework adapter internals, or simple event-driven modules where a full state library would be more structure than you need.

Avoid it when you need built-in selectors, reducers, devtools, persistence, async caching, normalized entities, or distributed synchronization. Those concerns can be built around the store, but they are not part of this package.

Documentation map

On this page