Choose state by purpose#
Use local signal() values inside views, @zidomjs/store for shared client state and @zidomjs/di for typed application services. These packages do not require the DOM runtime.
Shared stores#
import { createStore } from '@zidomjs/store';import { effect, flushSync } from '@zidomjs/core';const app = createStore({ passenger: 'Zidane', seat: '12A' });const summary = app.select(state => `${state.passenger} · ${state.seat}`);const stop = effect(() => console.log('seat:', app.state.seat));app.set('passenger', 'Amina'); // seat-only effect does not rerunapp.update('seat', old => old === '12A' ? '12B' : old);flushSync();console.log(summary.value);stop();app.dispose();Store tracking is top-level property selective, not deeply reactive. The state proxy is readonly; write with set, update, or patch. Replace nested objects immutably.
Typed dependency injection#
import { createContainer, createToken } from '@zidomjs/di';type ApiClient = { getName(): Promise<string> };const API = createToken<ApiClient>('api');const root = createContainer();root.registerFactory(API, () => ({ getName: async () => 'Zidom' }));const child = root.createChild();const api = child.get(API);console.log(await api.getName());child.dispose();root.dispose();Typed symbols identify services; containers support registration, factories, child overrides and disposal. createOwnedContainer() ties a container to a reactive scope when called inside one.
Scope and limitations#
A store is not an immutable state manager with history or deep proxies. DI is not an authentication or authorization system. Async factories, decorator scanning and advanced service lifetime models are not included yet.
Continue with Forms or the enterprise sample.
Run the example#
See the Zidom store example and inspect the exact source next to the result.