@homeostate/store-ngrx-signals
v0.1.2
Published
NgRx Signals adapter for @homeostate/core
Maintainers
Readme
@homeostate/store-ngrx-signals
NgRx Signals adapter for
@homeostate/core.
It keeps a slice of a signalState or signalStore in sync with a CRDT backend such as
Yjs, Loro or Automerge.
Install
npm install @homeostate/core @homeostate/store-ngrx-signals @homeostate/crdt-yjs @ngrx/signals yjs@angular/core 21 and @ngrx/signals 21 are peer dependencies.
Usage
injector is required: it owns the state watcher, so the engine can reconnect outside an
injection context. Capture it with inject(Injector):
import { DestroyRef, inject, Injector } from "@angular/core";
import { patchState, signalState } from "@ngrx/signals";
import { createSyncEngine } from "@homeostate/core";
import { createNgrxSignalsAdapter } from "@homeostate/store-ngrx-signals";
import { createYjsBackend } from "@homeostate/crdt-yjs";
import * as Y from "yjs";
const state = signalState({ shared: { count: 0 }, panelOpen: false });
const doc = new Y.Doc();
const adapter = createNgrxSignalsAdapter(state, {
select: (state) => state.shared,
replace: (shared) => patchState(state, { shared }),
injector: inject(Injector),
});
const engine = createSyncEngine(createYjsBackend(doc, "counter"), adapter);
engine.connect();
inject(DestroyRef).onDestroy(() => {
engine.disconnect();
doc.destroy();
});selectmust return the same object until the slice changes; update it immutably.replacemust replace the slice completely.patchStateshallow-merges, so keep synced data under one key such assharedand replace that key.- For a protected
signalStore, create the adapter insidewithHooksorwithMethods.
See the documentation for details.
License
MIT — see LICENSE.
