Introduces cacheableModels.js as the source of truth for which models the client caches in IDB and how to dispatch their revalidate actions. DataManager derives modelsToSync from the registry and creates object stores idempotently, so adding new cached models needs only one place to change plus a one-time DATA_VERSION bump. Also fixes two latent bugs that the upcoming boot-hydration relies on: setCacheKeys now awaits all per-key writes (was async-forEach with no await), and replace awaits clear before push (avoids ConstraintError on rapid refetches).
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// Single source of truth for IDB-cached workspace config.
|
|
//
|
|
// Each entry must keep `name` equal to the Rails `Model.name.underscore` value
|
|
// so the server's `cache_keys` payload (and the IDB object store name) lines up
|
|
// with what the client looks up.
|
|
//
|
|
// `dispatchPath` is the full Vuex dispatch path for the revalidate action.
|
|
// `setMutation` is the full commit path used by hydrateStoresFromCache to seed
|
|
// Vuex from IDB. `clearMutation` (optional) is committed BEFORE `setMutation`
|
|
// for modules whose SET_* mutation merges-by-id instead of replacing — without
|
|
// it, rows deleted server-side between sessions would survive as phantoms.
|
|
export const cacheableModels = [
|
|
{
|
|
name: 'inbox',
|
|
dispatchPath: 'inboxes/revalidate',
|
|
setMutation: 'inboxes/SET_INBOXES',
|
|
},
|
|
{
|
|
name: 'label',
|
|
dispatchPath: 'labels/revalidate',
|
|
setMutation: 'labels/SET_LABELS',
|
|
},
|
|
{
|
|
name: 'team',
|
|
dispatchPath: 'teams/revalidate',
|
|
setMutation: 'teams/SET_TEAMS',
|
|
clearMutation: 'teams/CLEAR_TEAMS',
|
|
},
|
|
{
|
|
name: 'canned_response',
|
|
dispatchPath: 'revalidateCannedResponses',
|
|
setMutation: 'SET_CANNED',
|
|
},
|
|
{
|
|
name: 'account_user',
|
|
dispatchPath: 'agents/revalidate',
|
|
setMutation: 'agents/SET_AGENTS',
|
|
},
|
|
];
|
|
|
|
export const cacheableModelNames = cacheableModels.map(model => model.name);
|