@magnetarjs/plugin-vue3
Version:
Magnetar plugin vue3
16 lines (15 loc) • 765 B
JavaScript
import { getPathWhereIdentifier } from '@magnetarjs/types';
import { merge } from 'merge-anything';
import { nestifyObject } from 'nestify-anything';
export function fetchAggregateActionFactory(pathAggregateDic, vue3StoreOptions) {
return function ({ payload, collectionPath, actionConfig, pluginModuleConfig, }) {
const pathId = getPathWhereIdentifier(collectionPath, pluginModuleConfig);
const doOnFetchSumAggregate = (count) => {
// abort updating local cache state if the payload was set to undefined
if (count === undefined)
return;
pathAggregateDic[pathId] = merge(pathAggregateDic[pathId], nestifyObject({ [payload]: count }));
};
return doOnFetchSumAggregate;
};
}