v-dict 2.0.7 → 2.0.8
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/react/index.cjs +3 -4
- package/dist/react/index.js +4 -5
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -242,13 +242,12 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
242
242
|
...useDictOptions
|
|
243
243
|
};
|
|
244
244
|
const { clone, immediate, refresh } = mergedOptions;
|
|
245
|
-
const stateRef = react.useRef(createStateFromMap());
|
|
246
245
|
const clonedLoadPromiseRef = react.useRef(null);
|
|
247
246
|
const globalMap = react.useSyncExternalStore(subscribeMap, getMapSnapshot);
|
|
248
247
|
const [clonedMap, setClonedMap] = react.useState(/* @__PURE__ */ new Map());
|
|
249
248
|
const loadPromise = !clone ? globalLoadPromise : clonedLoadPromiseRef.current;
|
|
250
249
|
const map = !clone ? globalMap : clonedMap;
|
|
251
|
-
const
|
|
250
|
+
const stateRef = react.useRef(createStateFromMap(map));
|
|
252
251
|
const load = react.useCallback((options) => {
|
|
253
252
|
const oldLoadPromise = loadPromise;
|
|
254
253
|
if (!clone) {
|
|
@@ -299,7 +298,7 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
299
298
|
}, []);
|
|
300
299
|
const ctx = react.useMemo(() => {
|
|
301
300
|
const value = {
|
|
302
|
-
...
|
|
301
|
+
...stateRef.current,
|
|
303
302
|
loadPromise,
|
|
304
303
|
load,
|
|
305
304
|
clear: clear2
|
|
@@ -312,7 +311,7 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
312
311
|
...extra == null ? void 0 : extra(value),
|
|
313
312
|
stateRef
|
|
314
313
|
};
|
|
315
|
-
}, [
|
|
314
|
+
}, [stateRef.current, loadPromise]);
|
|
316
315
|
return ctx;
|
|
317
316
|
}
|
|
318
317
|
useDict.extend = (extendCode2, extendOptions) => {
|
package/dist/react/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { warn, isFunction, cloneDeep, createPromise, toMap, merge, mapToObj, mapToList } from '../chunk-E7KZBQBQ.js';
|
|
2
2
|
export { defineDictData } from '../chunk-E7KZBQBQ.js';
|
|
3
|
-
import { useRef, useSyncExternalStore, useState,
|
|
3
|
+
import { useRef, useSyncExternalStore, useState, useCallback, useEffect, useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
function createDictManager(createDictManagerOptions = {}) {
|
|
6
6
|
const {
|
|
@@ -113,13 +113,12 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
113
113
|
...useDictOptions
|
|
114
114
|
};
|
|
115
115
|
const { clone, immediate, refresh } = mergedOptions;
|
|
116
|
-
const stateRef = useRef(createStateFromMap());
|
|
117
116
|
const clonedLoadPromiseRef = useRef(null);
|
|
118
117
|
const globalMap = useSyncExternalStore(subscribeMap, getMapSnapshot);
|
|
119
118
|
const [clonedMap, setClonedMap] = useState(/* @__PURE__ */ new Map());
|
|
120
119
|
const loadPromise = !clone ? globalLoadPromise : clonedLoadPromiseRef.current;
|
|
121
120
|
const map = !clone ? globalMap : clonedMap;
|
|
122
|
-
const
|
|
121
|
+
const stateRef = useRef(createStateFromMap(map));
|
|
123
122
|
const load = useCallback((options) => {
|
|
124
123
|
const oldLoadPromise = loadPromise;
|
|
125
124
|
if (!clone) {
|
|
@@ -170,7 +169,7 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
170
169
|
}, []);
|
|
171
170
|
const ctx = useMemo(() => {
|
|
172
171
|
const value = {
|
|
173
|
-
...
|
|
172
|
+
...stateRef.current,
|
|
174
173
|
loadPromise,
|
|
175
174
|
load,
|
|
176
175
|
clear: clear2
|
|
@@ -183,7 +182,7 @@ function createDictManager(createDictManagerOptions = {}) {
|
|
|
183
182
|
...extra == null ? void 0 : extra(value),
|
|
184
183
|
stateRef
|
|
185
184
|
};
|
|
186
|
-
}, [
|
|
185
|
+
}, [stateRef.current, loadPromise]);
|
|
187
186
|
return ctx;
|
|
188
187
|
}
|
|
189
188
|
useDict.extend = (extendCode2, extendOptions) => {
|