refactor: replace teams merge mutation with full replace
This commit is contained in:
@@ -6,9 +6,8 @@
|
||||
//
|
||||
// `dispatchPath` is the full Vuex dispatch path for the revalidate action.
|
||||
// `setMutation` is the full commit path used by paintStoresFromCache 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.
|
||||
// Vuex from IDB. Every SET_* mutation must REPLACE its records (not merge) so
|
||||
// rows deleted server-side never survive as phantoms.
|
||||
export const cacheableModels = [
|
||||
{
|
||||
name: 'inbox',
|
||||
@@ -24,7 +23,6 @@ export const cacheableModels = [
|
||||
name: 'team',
|
||||
dispatchPath: 'teams/revalidate',
|
||||
setMutation: 'teams/SET_TEAMS',
|
||||
clearMutation: 'teams/CLEAR_TEAMS',
|
||||
},
|
||||
{
|
||||
name: 'canned_response',
|
||||
|
||||
@@ -25,7 +25,6 @@ export default async function paintStoresFromCache(store, accountId) {
|
||||
cacheableModels.map(async model => {
|
||||
const localData = await dm.get({ modelName: model.name });
|
||||
if (localData.length === 0) return;
|
||||
if (model.clearMutation) store.commit(model.clearMutation);
|
||||
store.commit(model.setMutation, localData);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('paintStoresFromCache', () => {
|
||||
expect(storeMock.dispatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('commits CLEAR_TEAMS before SET_TEAMS to drop phantom rows', async () => {
|
||||
it('seeds teams via SET_TEAMS', async () => {
|
||||
await dm.push({
|
||||
modelName: 'team',
|
||||
data: [{ id: 1, name: 'Sales' }],
|
||||
@@ -72,10 +72,8 @@ describe('paintStoresFromCache', () => {
|
||||
|
||||
await paintStoresFromCache(storeMock, accountId);
|
||||
|
||||
const teamCommits = storeMock.commit.mock.calls.filter(call =>
|
||||
call[0].startsWith('teams/')
|
||||
);
|
||||
expect(teamCommits[0][0]).toBe('teams/CLEAR_TEAMS');
|
||||
expect(teamCommits[1][0]).toBe('teams/SET_TEAMS');
|
||||
expect(storeMock.commit).toHaveBeenCalledWith('teams/SET_TEAMS', [
|
||||
{ id: 1, name: 'Sales' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user