floppy-disk 2.0.0-alpha.3 → 2.0.0-beta.1
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/README.md
CHANGED
|
@@ -663,7 +663,17 @@ const useCartStore = createStore(({ set, get }) => ({
|
|
|
663
663
|
}));
|
|
664
664
|
```
|
|
665
665
|
|
|
666
|
-
|
|
666
|
+
Don't use conditional reactivity selector.
|
|
667
|
+
|
|
668
|
+
```jsx
|
|
669
|
+
function Cat({ isSomething }) {
|
|
670
|
+
const { age } = useCatStore(isSomething ? (state) => [state.age] : null); // ❌
|
|
671
|
+
const { age } = useCatStore((state) => (isSomething ? [state.age] : [state.isSleeping])); // ❌
|
|
672
|
+
return <div>Cat's age: {age}</div>;
|
|
673
|
+
}
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
No need to memoize the reactivity selector.
|
|
667
677
|
|
|
668
678
|
```jsx
|
|
669
679
|
function Cat() {
|
|
@@ -673,11 +683,12 @@ function Cat() {
|
|
|
673
683
|
}
|
|
674
684
|
```
|
|
675
685
|
|
|
676
|
-
|
|
686
|
+
No need to memoize the store key / query key.
|
|
677
687
|
|
|
678
688
|
```jsx
|
|
679
|
-
function
|
|
680
|
-
const
|
|
681
|
-
|
|
689
|
+
function PokemonsPage() {
|
|
690
|
+
const queryKey = useMemo(() => ({ generation: 'ii', sort: 'asc' }), []); // ❌
|
|
691
|
+
const { isLoading, data } = usePokemonsQuery(queryKey);
|
|
692
|
+
return <div>...</div>;
|
|
682
693
|
}
|
|
683
694
|
```
|
|
@@ -21,7 +21,6 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
21
21
|
* You can ignore this if your query is not paginated.
|
|
22
22
|
*/
|
|
23
23
|
fetchNextPage: () => void;
|
|
24
|
-
markAsStale: () => void;
|
|
25
24
|
/**
|
|
26
25
|
* Set query state (data, error, etc) to initial state.
|
|
27
26
|
*/
|
|
@@ -153,6 +152,14 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
153
152
|
key?: TKey;
|
|
154
153
|
response: TResponse;
|
|
155
154
|
}) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Set query state (data, error, etc) to initial state.
|
|
157
|
+
*/
|
|
158
|
+
reset: () => void;
|
|
159
|
+
/**
|
|
160
|
+
* Set query state (data, error, etc) to initial state.
|
|
161
|
+
*/
|
|
162
|
+
resetSpecificKey: (key?: TKey | null) => void;
|
|
156
163
|
/**
|
|
157
164
|
* Invalidate query means marking a query as stale, and will refetch only if the query is active (has subscriber)
|
|
158
165
|
*/
|
|
@@ -206,7 +206,6 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
206
206
|
fetch,
|
|
207
207
|
forceFetch,
|
|
208
208
|
fetchNextPage,
|
|
209
|
-
markAsStale: () => set({ responseUpdatedAt: null }),
|
|
210
209
|
reset: () => set(INITIAL_QUERY_STATE),
|
|
211
210
|
};
|
|
212
211
|
}, (() => {
|
|
@@ -283,6 +282,15 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
283
282
|
});
|
|
284
283
|
});
|
|
285
284
|
};
|
|
285
|
+
useQuery.reset = () => {
|
|
286
|
+
useQuery.getStores().forEach((store) => {
|
|
287
|
+
store.set(INITIAL_QUERY_STATE);
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
useQuery.resetSpecificKey = (key) => {
|
|
291
|
+
const store = useQuery.getStore(key);
|
|
292
|
+
store.set(INITIAL_QUERY_STATE);
|
|
293
|
+
};
|
|
286
294
|
useQuery.invalidate = () => {
|
|
287
295
|
useQuery.getStores().forEach((store) => {
|
|
288
296
|
const { set, getSubscribers } = store;
|
|
@@ -21,7 +21,6 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
21
21
|
* You can ignore this if your query is not paginated.
|
|
22
22
|
*/
|
|
23
23
|
fetchNextPage: () => void;
|
|
24
|
-
markAsStale: () => void;
|
|
25
24
|
/**
|
|
26
25
|
* Set query state (data, error, etc) to initial state.
|
|
27
26
|
*/
|
|
@@ -153,6 +152,14 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
153
152
|
key?: TKey;
|
|
154
153
|
response: TResponse;
|
|
155
154
|
}) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Set query state (data, error, etc) to initial state.
|
|
157
|
+
*/
|
|
158
|
+
reset: () => void;
|
|
159
|
+
/**
|
|
160
|
+
* Set query state (data, error, etc) to initial state.
|
|
161
|
+
*/
|
|
162
|
+
resetSpecificKey: (key?: TKey | null) => void;
|
|
156
163
|
/**
|
|
157
164
|
* Invalidate query means marking a query as stale, and will refetch only if the query is active (has subscriber)
|
|
158
165
|
*/
|
|
@@ -209,7 +209,6 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
209
209
|
fetch,
|
|
210
210
|
forceFetch,
|
|
211
211
|
fetchNextPage,
|
|
212
|
-
markAsStale: () => set({ responseUpdatedAt: null }),
|
|
213
212
|
reset: () => set(INITIAL_QUERY_STATE),
|
|
214
213
|
};
|
|
215
214
|
}, (() => {
|
|
@@ -286,6 +285,15 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
286
285
|
});
|
|
287
286
|
});
|
|
288
287
|
};
|
|
288
|
+
useQuery.reset = () => {
|
|
289
|
+
useQuery.getStores().forEach((store) => {
|
|
290
|
+
store.set(INITIAL_QUERY_STATE);
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
useQuery.resetSpecificKey = (key) => {
|
|
294
|
+
const store = useQuery.getStore(key);
|
|
295
|
+
store.set(INITIAL_QUERY_STATE);
|
|
296
|
+
};
|
|
289
297
|
useQuery.invalidate = () => {
|
|
290
298
|
useQuery.getStores().forEach((store) => {
|
|
291
299
|
const { set, getSubscribers } = store;
|