CreateChimericSyncFactory
Provided by @chimeric/react.
Creates a reusable factory bound to a state management library (Redux, Zustand, etc.) via an adapter. This is the recommended way to create ChimericSync instances.
import { CreateChimericSyncFactory } from '@chimeric/react';With Zustand
Section titled “With Zustand”import { create } from 'zustand';
const useTodoStore = create<TodoStore>((set) => ({ ... }));
const ChimericSyncFactory = CreateChimericSyncFactory<TodoStore>({ getState: () => useTodoStore.getState(), useSelector: useTodoStore,});
// Create sync operations from the factoryconst getTodoById = ChimericSyncFactory({ selector: (params: { id: string }) => (state) => state.dict[params.id], reducer: (record) => (record ? toDomain(record) : undefined),});With Redux
Section titled “With Redux”import { useAppSelector } from './hooks';import { appStore } from './store';
const ChimericSyncFactory = CreateChimericSyncFactory({ getState: () => appStore.getState(), useSelector: useAppSelector,});
const getActiveCount = ChimericSyncFactory({ selector: () => (state) => state.todos.filter((t) => !t.completed).length,});Adapter Config
Section titled “Adapter Config”| Property | Type | Description |
|---|---|---|
getState | () => TState | Synchronous state accessor |
useSelector | <T>(selector: (state: TState) => T) => T | React hook for subscribing to state |
Factory Config
Section titled “Factory Config”| Property | Type | Description |
|---|---|---|
selector | (params) => (state) => TSelected | Selector factory — takes params, returns a state selector |
reducer | (selected, params) => TResult | Optional. Transform the selected value before returning. |
// Idiomatic — reads directly from the storeconst todo = getTodoById({ id: '123' });
// Reactive — subscribes to store updates via the hookconst todo = getTodoById.useHook({ id: '123' });See the RTK SPA example and Next.js example for real-world usage.