⚠️ Version 2.x introduces breaking changes compared to 1.x
See MIGRATION_v1_to_v2.md for details.
A minimal reactive state manager for projects where you want simple shared state without overhead.
<script src="https://cdn.jsdelivr.net/npm/observable-store-light@2.0.1/dist/index.min.js"></script>
-
Observer-based state updates Components automatically re-render when a subscribed value changes.
-
Zero dependencies Nothing extra in your bundle.
-
Fully typed with TypeScript Strong typing for keys and values out of the box.
-
Can be used from JavaScript projects TypeScript is optional — works perfectly in JS ESM modules or single module CommonJS.
-
Supports multiple independent stores Create as many stores as you need — each one is fully isolated.
-
State flexibility Does not enforce state serialization.
You can store any JavaScript values in the store:
- primitives
- objects and arrays
- class instances
- functions
- DOM references
- non-serializable values
-
Tiny bundle size
npm install observable-store-lightor
pnpm add observable-store-light-
createStore: (initData: T) Creates a new isolated store instance.
-
addListener: (key: K) => T[K] Attach listener to a specific store key.
-
removeListener: (key: K) => T[K] Attach listener to a specific store key.
-
get: (key: K) => T[K] Reads the value by key.
-
set: (key: K, value: T[K], isCallListener?: boolean = true) => void Updates a value by key and calls listeners optional.
Create store
import { createStore } from "observable-store-light";
const store = createStore({
count: 1,
});Attach listener
let name = '';
let value = 0;
addListener('count', (_name, _value) => {
name = _name;
value = _value;
});
console.log(name, value) // 'count', 1const currentCount = store.get('count');
store.set('count', currentCount + 1);
console.log(value) // 2const authStore = createStore({
isAuthenticated: false,
});
const settingsStore = createStore({
theme: "dark",
});Each store is completely independent and has its own state and subscriptions.
MIT
Denis Kurochkin