v-dict 1.1.1 → 1.1.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/create-promise.d.ts +1 -0
- package/dist/index.cjs +20 -6
- package/dist/index.js +20 -6
- package/package.json +1 -1
package/dist/create-promise.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export type Reject = (reason?: any) => void;
|
|
|
3
3
|
export type CreatePromiseReturn<T> = Promise<T> & {
|
|
4
4
|
resolve: Resolve<T>;
|
|
5
5
|
reject: Reject;
|
|
6
|
+
isPending: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare function createPromise<T = any>(executor?: (resolve: Resolve<T>, reject: Reject) => void): CreatePromiseReturn<T>;
|
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,10 @@ function createPromise(executor) {
|
|
|
18
18
|
});
|
|
19
19
|
promise.resolve = resolve;
|
|
20
20
|
promise.reject = reject;
|
|
21
|
+
promise.isPending = true;
|
|
22
|
+
promise.finally(() => {
|
|
23
|
+
promise.isPending = false;
|
|
24
|
+
});
|
|
21
25
|
return promise;
|
|
22
26
|
}
|
|
23
27
|
function clearObj(obj) {
|
|
@@ -79,8 +83,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
79
83
|
fetch = managerFetch,
|
|
80
84
|
extra
|
|
81
85
|
} = (_a = lodashEs.isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions) != null ? _a : {};
|
|
82
|
-
|
|
83
|
-
const managerLoadPromise = vue.shallowRef(createPromise());
|
|
86
|
+
const globalLoadPromise = vue.shallowRef(null);
|
|
84
87
|
maps[code] = /* @__PURE__ */ new Map();
|
|
85
88
|
async function loadDict(options, mapRef) {
|
|
86
89
|
var _a2;
|
|
@@ -96,13 +99,11 @@ function createDictManager(managerOptions = {}) {
|
|
|
96
99
|
} else {
|
|
97
100
|
mapRef.value = dataMap;
|
|
98
101
|
}
|
|
99
|
-
managerLoaded = true;
|
|
100
102
|
}
|
|
101
103
|
return (useDictOptions) => {
|
|
102
104
|
useDictOptions = lodashEs.merge({ clone: false, immediate: true, refresh: false }, useDictOptions);
|
|
103
105
|
const { clone, immediate, refresh } = useDictOptions;
|
|
104
|
-
|
|
105
|
-
const loadPromise = !clone ? managerLoadPromise : vue.shallowRef(createPromise());
|
|
106
|
+
const loadPromise = !clone ? globalLoadPromise : vue.shallowRef(createPromise());
|
|
106
107
|
const mapRef = !clone ? vue.toRef(maps, code) : vue.ref(/* @__PURE__ */ new Map());
|
|
107
108
|
const objRef = vue.ref({});
|
|
108
109
|
const listRef = vue.ref([]);
|
|
@@ -122,8 +123,21 @@ function createDictManager(managerOptions = {}) {
|
|
|
122
123
|
return result;
|
|
123
124
|
});
|
|
124
125
|
if (!remote || immediate) {
|
|
125
|
-
if (
|
|
126
|
+
if (clone) {
|
|
126
127
|
load();
|
|
128
|
+
} else {
|
|
129
|
+
if (!globalLoadPromise.value) {
|
|
130
|
+
globalLoadPromise.value = createPromise();
|
|
131
|
+
load();
|
|
132
|
+
} else {
|
|
133
|
+
globalLoadPromise.value.then(() => {
|
|
134
|
+
refresh && load();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
if (!globalLoadPromise.value) {
|
|
140
|
+
globalLoadPromise.value = createPromise();
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
function load(options) {
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,10 @@ function createPromise(executor) {
|
|
|
16
16
|
});
|
|
17
17
|
promise.resolve = resolve;
|
|
18
18
|
promise.reject = reject;
|
|
19
|
+
promise.isPending = true;
|
|
20
|
+
promise.finally(() => {
|
|
21
|
+
promise.isPending = false;
|
|
22
|
+
});
|
|
19
23
|
return promise;
|
|
20
24
|
}
|
|
21
25
|
function clearObj(obj) {
|
|
@@ -77,8 +81,7 @@ function createDictManager(managerOptions = {}) {
|
|
|
77
81
|
fetch = managerFetch,
|
|
78
82
|
extra
|
|
79
83
|
} = (_a = isFunction(defineDictOptions) ? defineDictOptions() : defineDictOptions) != null ? _a : {};
|
|
80
|
-
|
|
81
|
-
const managerLoadPromise = shallowRef(createPromise());
|
|
84
|
+
const globalLoadPromise = shallowRef(null);
|
|
82
85
|
maps[code] = /* @__PURE__ */ new Map();
|
|
83
86
|
async function loadDict(options, mapRef) {
|
|
84
87
|
var _a2;
|
|
@@ -94,13 +97,11 @@ function createDictManager(managerOptions = {}) {
|
|
|
94
97
|
} else {
|
|
95
98
|
mapRef.value = dataMap;
|
|
96
99
|
}
|
|
97
|
-
managerLoaded = true;
|
|
98
100
|
}
|
|
99
101
|
return (useDictOptions) => {
|
|
100
102
|
useDictOptions = merge({ clone: false, immediate: true, refresh: false }, useDictOptions);
|
|
101
103
|
const { clone, immediate, refresh } = useDictOptions;
|
|
102
|
-
|
|
103
|
-
const loadPromise = !clone ? managerLoadPromise : shallowRef(createPromise());
|
|
104
|
+
const loadPromise = !clone ? globalLoadPromise : shallowRef(createPromise());
|
|
104
105
|
const mapRef = !clone ? toRef(maps, code) : ref(/* @__PURE__ */ new Map());
|
|
105
106
|
const objRef = ref({});
|
|
106
107
|
const listRef = ref([]);
|
|
@@ -120,8 +121,21 @@ function createDictManager(managerOptions = {}) {
|
|
|
120
121
|
return result;
|
|
121
122
|
});
|
|
122
123
|
if (!remote || immediate) {
|
|
123
|
-
if (
|
|
124
|
+
if (clone) {
|
|
124
125
|
load();
|
|
126
|
+
} else {
|
|
127
|
+
if (!globalLoadPromise.value) {
|
|
128
|
+
globalLoadPromise.value = createPromise();
|
|
129
|
+
load();
|
|
130
|
+
} else {
|
|
131
|
+
globalLoadPromise.value.then(() => {
|
|
132
|
+
refresh && load();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
if (!globalLoadPromise.value) {
|
|
138
|
+
globalLoadPromise.value = createPromise();
|
|
125
139
|
}
|
|
126
140
|
}
|
|
127
141
|
function load(options) {
|