v-dict 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -7
- package/dist/index.js +6 -7
- package/dist/types/dict.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -97,15 +97,15 @@ function createDictManager(managerOptions = {}) {
|
|
|
97
97
|
clearObj(maps);
|
|
98
98
|
}
|
|
99
99
|
function _defineDict(internalOptions, code, defineDictOptions) {
|
|
100
|
+
const { pickValues, omitValues, extendCode } = internalOptions;
|
|
100
101
|
if (maps[code]) {
|
|
101
102
|
warn(`code "${code}" already exists`);
|
|
102
103
|
}
|
|
103
|
-
const { pickValues, omitValues } = internalOptions;
|
|
104
104
|
const options = Object.assign(
|
|
105
105
|
{ data: {}, remote: false, fetch: managerFetch },
|
|
106
106
|
lodashEs.isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions
|
|
107
107
|
);
|
|
108
|
-
defineDictOptionsMap.set(code, options);
|
|
108
|
+
defineDictOptionsMap.set(code, lodashEs.cloneDeep(options));
|
|
109
109
|
const { data, remote, fetch, extra } = options;
|
|
110
110
|
const globalLoadPromise = vue.shallowRef(null);
|
|
111
111
|
maps[code] = /* @__PURE__ */ new Map();
|
|
@@ -113,7 +113,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
113
113
|
var _a;
|
|
114
114
|
const dataMap = toMap(lodashEs.cloneDeep(data), { pickValues, omitValues });
|
|
115
115
|
if (remote) {
|
|
116
|
-
const res = (_a = await (fetch == null ? void 0 : fetch(code, options2))) != null ? _a : [];
|
|
116
|
+
const res = (_a = await (fetch == null ? void 0 : fetch(extendCode != null ? extendCode : code, options2))) != null ? _a : [];
|
|
117
117
|
mapRef.value = toMap(res, { pickValues, omitValues });
|
|
118
118
|
dataMap.forEach((value, key) => {
|
|
119
119
|
if (mapRef.value.has(key)) {
|
|
@@ -198,11 +198,10 @@ function createDictManager(managerOptions = {}) {
|
|
|
198
198
|
...extra == null ? void 0 : extra(reactiveCtx)
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
|
-
|
|
202
|
-
useDict.extend = (code2, extendOptions) => {
|
|
201
|
+
useDict.extend = (extendCode2, extendOptions) => {
|
|
203
202
|
const { pickValues: pickValues2, omitValues: omitValues2 } = extendOptions != null ? extendOptions : {};
|
|
204
|
-
const options2 = defineDictOptionsMap.get(
|
|
205
|
-
return _defineDict
|
|
203
|
+
const options2 = defineDictOptionsMap.get(code);
|
|
204
|
+
return _defineDict({ pickValues: pickValues2, omitValues: omitValues2, extendCode: code }, extendCode2, options2);
|
|
206
205
|
};
|
|
207
206
|
return useDict;
|
|
208
207
|
}
|
package/dist/index.js
CHANGED
|
@@ -95,15 +95,15 @@ function createDictManager(managerOptions = {}) {
|
|
|
95
95
|
clearObj(maps);
|
|
96
96
|
}
|
|
97
97
|
function _defineDict(internalOptions, code, defineDictOptions) {
|
|
98
|
+
const { pickValues, omitValues, extendCode } = internalOptions;
|
|
98
99
|
if (maps[code]) {
|
|
99
100
|
warn(`code "${code}" already exists`);
|
|
100
101
|
}
|
|
101
|
-
const { pickValues, omitValues } = internalOptions;
|
|
102
102
|
const options = Object.assign(
|
|
103
103
|
{ data: {}, remote: false, fetch: managerFetch },
|
|
104
104
|
isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions
|
|
105
105
|
);
|
|
106
|
-
defineDictOptionsMap.set(code, options);
|
|
106
|
+
defineDictOptionsMap.set(code, cloneDeep(options));
|
|
107
107
|
const { data, remote, fetch, extra } = options;
|
|
108
108
|
const globalLoadPromise = shallowRef(null);
|
|
109
109
|
maps[code] = /* @__PURE__ */ new Map();
|
|
@@ -111,7 +111,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
111
111
|
var _a;
|
|
112
112
|
const dataMap = toMap(cloneDeep(data), { pickValues, omitValues });
|
|
113
113
|
if (remote) {
|
|
114
|
-
const res = (_a = await (fetch == null ? void 0 : fetch(code, options2))) != null ? _a : [];
|
|
114
|
+
const res = (_a = await (fetch == null ? void 0 : fetch(extendCode != null ? extendCode : code, options2))) != null ? _a : [];
|
|
115
115
|
mapRef.value = toMap(res, { pickValues, omitValues });
|
|
116
116
|
dataMap.forEach((value, key) => {
|
|
117
117
|
if (mapRef.value.has(key)) {
|
|
@@ -196,11 +196,10 @@ function createDictManager(managerOptions = {}) {
|
|
|
196
196
|
...extra == null ? void 0 : extra(reactiveCtx)
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
|
-
|
|
200
|
-
useDict.extend = (code2, extendOptions) => {
|
|
199
|
+
useDict.extend = (extendCode2, extendOptions) => {
|
|
201
200
|
const { pickValues: pickValues2, omitValues: omitValues2 } = extendOptions != null ? extendOptions : {};
|
|
202
|
-
const options2 = defineDictOptionsMap.get(
|
|
203
|
-
return _defineDict
|
|
201
|
+
const options2 = defineDictOptionsMap.get(code);
|
|
202
|
+
return _defineDict({ pickValues: pickValues2, omitValues: omitValues2, extendCode: code }, extendCode2, options2);
|
|
204
203
|
};
|
|
205
204
|
return useDict;
|
|
206
205
|
}
|
package/dist/types/dict.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ type ExtractFetchOptions<F extends Fetch> = Parameters<F>[1] extends infer T ? T
|
|
|
27
27
|
type ExtractFetchReturn<F extends Fetch> = UnwrapArray<Awaited<ReturnType<F>>> extends infer Item ? Item extends never ? {} : Item : never;
|
|
28
28
|
type _UseDict<ME extends ExtraGetter, E extends ExtraGetter, D extends Recordable, F extends Fetch> = (options?: Simplify<UseDictOptions & ExtractFetchOptions<F>>) => Simplify<CreateDict<D, F> & ReturnType<ME> & ReturnType<E>>;
|
|
29
29
|
type UseDict<ME extends ExtraGetter, E extends ExtraGetter, D extends Recordable, F extends Fetch> = _UseDict<ME, E, D, F> & {
|
|
30
|
-
extend: (
|
|
30
|
+
extend: (extendCode: string, extendOptions?: {
|
|
31
31
|
pickValues?: Simplify<keyof D>[];
|
|
32
32
|
omitValues?: Simplify<keyof D>[];
|
|
33
33
|
}) => UseDict<ME, E, D, F>;
|