Skip to content

@jsvision/datagrid / createMemoryVariantStore

Function: createMemoryVariantStore()

createMemoryVariantStore(initial?): VariantStore

Defined in: datagrid/src/variant-store.ts:56

A reference in-memory VariantStore — an array of variants plus an optional default name. Real persistence is the app's job; this one is enough for a showcase or a test. save overwrites by name (order preserved on replace, appended for a new name), delete of the current default clears the default, and list() returns a fresh copy so a caller cannot mutate the store's array in place.

Parameters

initial?

readonly GridVariant[]

Variants to seed the store with (defensively copied); no default is set initially.

Returns

VariantStore

A live in-memory store.

Example

ts
import { createMemoryVariantStore, type GridVariant } from '@jsvision/datagrid';

const compact: GridVariant = {
  name: 'compact',
  columns: [{ id: 'name', visible: true }],
  freeze: { left: [], right: [] },
  sort: [],
  filter: [],
};
const wide: GridVariant = { ...compact, name: 'wide' };

const store = createMemoryVariantStore([compact, wide]);
store.setDefault('compact');
store.getDefault();      // 'compact'
store.delete('compact'); // removes it AND clears the default
store.getDefault();      // undefined