Grid selector subscriptions
experimental
Track three independent state selections and compare reference equality with shallow equality.
Live example
Expected behavior
Selection, sorting and row-count widgets update only when their selected values change. An unsubscribed widget keeps its final counter.
Source
import { createGrid } from '@warlockcode/warui-core';
const api = createGrid({ rows: [{ id: 1 }], columns: [] });
const remove = api.subscribe(
state => state.selection.rowIds.length,
selected => console.log(selected),
{ fireImmediately: true },
);
api.setSelection(['1']);
remove();
import { createGrid } from '@warlockcode/warui-core';
const api = createGrid({ rows: [{ id: 1 }], columns: [] });
const remove = api.subscribe(
state => state.selection.rowIds.length,
selected => console.log(selected),
{ fireImmediately: true },
);
api.setSelection(['1']);
remove();
import { createGrid } from '@warlockcode/warui-core';
const api = createGrid({ rows: [{ id: 1 }], columns: [] });
const remove = api.subscribe(
state => state.selection.rowIds.length,
selected => console.log(selected),
{ fireImmediately: true },
);
api.setSelection(['1']);
remove();
import { createGrid } from '@warlockcode/warui-core';
const api = createGrid({ rows: [{ id: 1 }], columns: [] });
const remove = api.subscribe(
state => state.selection.rowIds.length,
selected => console.log(selected),
{ fireImmediately: true },
);
api.setSelection(['1']);
remove();
// JavaScript module for Blazor interop
import { createGrid } from '@warlockcode/warui-core';
const api = createGrid({ rows: [{ id: 1 }], columns: [] });
const remove = api.subscribe(
state => state.selection.rowIds.length,
selected => console.log(selected),
{ fireImmediately: true },
);
api.setSelection(['1']);
remove();
API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Method | select | — | Reads a derived value from the last committed snapshot. |
| Method | subscribe | — | Runs the listener after committed changes that pass the equality check. |
| Type | SubscribeOptions | — | Supports custom equalityFn and synchronous fireImmediately. |