UNPKG

tav-ui

Version:
54 lines (49 loc) 2.25 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('../../utils/index2.js'); var validate = require('../../utils/validate2.js'); function useDataSource(options) { const { mergedProps, emits, VersionCachesController, dataSource } = options; async function handleDataSourceChangeEmit(rows, emits2, mergedProps2, VersionCachesController2) { const dataSource2 = rows; if (mergedProps2.value.mode === "update" || mergedProps2.value.mode === "updateInstantly") { emits2("actualidsChange", VersionCachesController2.getCaches()); } else { emits2("actualidsChange", dataSource2.map((file) => file.actualId)); } } vue.onMounted(() => { vue.watch(() => JSON.stringify(dataSource.value), async (curdatasource, predatasource) => { if (curdatasource && curdatasource !== predatasource) { const rows = JSON.parse(JSON.stringify([...dataSource.value ?? []])); if (rows.length > 0) { VersionCachesController.createAllFileCaches(rows, mergedProps.value.mode); if (validate.validateDataSourceIsObjectArray(mergedProps.value.dataSource)) { const _dataSource = mergedProps.value.dataSource; _dataSource.forEach((data) => { const row = rows.find((r) => r.actualId === data.actualId); const versionList = data.versionList; if (row && versionList) { VersionCachesController.createFileCaches(row, versionList); } if (mergedProps.value.mode === "update" && validate.validateVersionCachesHasApiFile(VersionCachesController.caches[data.actualId]) && validate.validateVersionCachesHasLocalFile(VersionCachesController.caches[data.actualId])) { VersionCachesController.actualidCaches.add(data.actualId); } }); } } else { VersionCachesController.deleteAllFileCaches(); } await handleDataSourceChangeEmit(rows, emits, mergedProps, VersionCachesController); } }, { immediate: true }); }); return { handleDataSourceChangeEmit }; } exports.useDataSource = useDataSource; //# sourceMappingURL=use-data-source2.js.map