Quick Start
-
Install the package:
Terminal window npm install dharma-coreTerminal window pnpm add dharma-coreTerminal window yarn add dharma-core -
Create a store:
import { createStore } from "dharma-core";const store = createStore({initialState: { count: 0 },actions: ({ set }) => ({increment: () => set((state) => ({ count: state.count + 1 })),decrement: () => set((state) => ({ count: state.count - 1 })),}),});const { increment, decrement } = store.actions; -
Subscribe to the store and update its state by calling actions:
// Subscribe to state changesconst unsubscribe = store.subscribe((state) => console.log(state));// Update the stateincrement();// { count: 1 }decrement();// { count: 0 }unsubscribe();