floppy-disk 2.1.0-beta.1 → 2.1.0-beta.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/esm/preact/create-query.js +7 -7
- package/esm/preact/create-stores.d.ts +4 -0
- package/esm/preact/create-stores.js +2 -1
- package/esm/react/create-query.js +7 -7
- package/esm/react/create-stores.d.ts +4 -0
- package/esm/react/create-stores.js +2 -1
- package/esm/utils/index.d.ts +2 -1
- package/esm/utils/index.js +2 -1
- package/lib/preact/create-query.js +6 -6
- package/lib/preact/create-stores.d.ts +4 -0
- package/lib/preact/create-stores.js +2 -1
- package/lib/react/create-query.js +6 -6
- package/lib/react/create-stores.d.ts +4 -0
- package/lib/react/create-stores.js +2 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +4 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'preact/hooks';
|
|
2
|
-
import { identityFn, noop } from '../utils';
|
|
2
|
+
import { hasValue, identityFn, noop } from '../utils';
|
|
3
3
|
import { createStores } from './create-stores';
|
|
4
4
|
const getDecision = (value, param, { ifTrue, ifAlways }) => {
|
|
5
5
|
if (value === true || (typeof value === 'function' && value(param) === true)) {
|
|
@@ -84,7 +84,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
84
84
|
responseAllPages.push(response);
|
|
85
85
|
const newPageParam = getNextPageParam(response, responseAllPages.length);
|
|
86
86
|
newPageParams.push(newPageParam);
|
|
87
|
-
if (newPageParam
|
|
87
|
+
if (hasValue(newPageParam) && newPageParams.length < pageParams.length) {
|
|
88
88
|
pageParam = newPageParam;
|
|
89
89
|
callQuery();
|
|
90
90
|
return;
|
|
@@ -109,7 +109,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
109
109
|
retryCount: 0,
|
|
110
110
|
pageParam: newPageParam,
|
|
111
111
|
pageParams: newPageParams,
|
|
112
|
-
hasNextPage: newPageParam
|
|
112
|
+
hasNextPage: hasValue(newPageParam),
|
|
113
113
|
});
|
|
114
114
|
onSuccess(response, stateBeforeCallQuery);
|
|
115
115
|
})
|
|
@@ -131,7 +131,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
131
131
|
errorUpdatedAt,
|
|
132
132
|
isGoingToRetry: shouldRetry,
|
|
133
133
|
pageParam,
|
|
134
|
-
hasNextPage: pageParam
|
|
134
|
+
hasNextPage: hasValue(pageParam),
|
|
135
135
|
}
|
|
136
136
|
: {
|
|
137
137
|
isWaiting: false,
|
|
@@ -142,7 +142,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
142
142
|
errorUpdatedAt,
|
|
143
143
|
isGoingToRetry: shouldRetry,
|
|
144
144
|
pageParam,
|
|
145
|
-
hasNextPage: pageParam
|
|
145
|
+
hasNextPage: hasValue(pageParam),
|
|
146
146
|
});
|
|
147
147
|
if (shouldRetry) {
|
|
148
148
|
retryTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
@@ -184,7 +184,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
184
184
|
data: select(response, { key, data }),
|
|
185
185
|
pageParam: newPageParam,
|
|
186
186
|
pageParams: pageParams.concat(newPageParam),
|
|
187
|
-
hasNextPage: newPageParam
|
|
187
|
+
hasNextPage: hasValue(newPageParam),
|
|
188
188
|
});
|
|
189
189
|
})
|
|
190
190
|
.catch((error) => {
|
|
@@ -287,7 +287,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
287
287
|
data: select(response, { key: key, data: null }),
|
|
288
288
|
pageParam: newPageParam,
|
|
289
289
|
pageParams: [undefined, newPageParam],
|
|
290
|
-
hasNextPage: newPageParam
|
|
290
|
+
hasNextPage: hasValue(newPageParam),
|
|
291
291
|
});
|
|
292
292
|
});
|
|
293
293
|
};
|
|
@@ -39,6 +39,10 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
39
39
|
};
|
|
40
40
|
export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = InitStoreOptions<T> & {
|
|
41
41
|
onBeforeChangeKey?: (nextKey: TKey, prevKey: TKey) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Will be triggered when a single store with a specific key was initialized.
|
|
44
|
+
*/
|
|
45
|
+
onStoreInitialized?: (key: TKey, keyHash: string) => void;
|
|
42
46
|
defaultDeps?: SelectDeps<T>;
|
|
43
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
44
48
|
};
|
|
@@ -2,13 +2,14 @@ import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
|
2
2
|
import { hashStoreKey, noop } from '../utils';
|
|
3
3
|
import { initStore, } from '../vanilla';
|
|
4
4
|
export const createStores = (initializer, options = {}) => {
|
|
5
|
-
const { onBeforeChangeKey = noop, defaultDeps, hashKeyFn = hashStoreKey } = options;
|
|
5
|
+
const { onBeforeChangeKey = noop, onStoreInitialized = noop, defaultDeps, hashKeyFn = hashStoreKey, } = options;
|
|
6
6
|
const stores = new Map();
|
|
7
7
|
const getStore = (_key) => {
|
|
8
8
|
const key = _key || {};
|
|
9
9
|
const keyHash = hashKeyFn(key);
|
|
10
10
|
if (!stores.has(keyHash)) {
|
|
11
11
|
stores.set(keyHash, initStore((api) => initializer({ key, keyHash, ...api }), options));
|
|
12
|
+
onStoreInitialized(key, keyHash);
|
|
12
13
|
}
|
|
13
14
|
return stores.get(keyHash);
|
|
14
15
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { identityFn, noop } from '../utils';
|
|
2
|
+
import { hasValue, identityFn, noop } from '../utils';
|
|
3
3
|
import { createStores } from './create-stores';
|
|
4
4
|
const getDecision = (value, param, { ifTrue, ifAlways }) => {
|
|
5
5
|
if (value === true || (typeof value === 'function' && value(param) === true)) {
|
|
@@ -84,7 +84,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
84
84
|
responseAllPages.push(response);
|
|
85
85
|
const newPageParam = getNextPageParam(response, responseAllPages.length);
|
|
86
86
|
newPageParams.push(newPageParam);
|
|
87
|
-
if (newPageParam
|
|
87
|
+
if (hasValue(newPageParam) && newPageParams.length < pageParams.length) {
|
|
88
88
|
pageParam = newPageParam;
|
|
89
89
|
callQuery();
|
|
90
90
|
return;
|
|
@@ -109,7 +109,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
109
109
|
retryCount: 0,
|
|
110
110
|
pageParam: newPageParam,
|
|
111
111
|
pageParams: newPageParams,
|
|
112
|
-
hasNextPage: newPageParam
|
|
112
|
+
hasNextPage: hasValue(newPageParam),
|
|
113
113
|
});
|
|
114
114
|
onSuccess(response, stateBeforeCallQuery);
|
|
115
115
|
})
|
|
@@ -131,7 +131,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
131
131
|
errorUpdatedAt,
|
|
132
132
|
isGoingToRetry: shouldRetry,
|
|
133
133
|
pageParam,
|
|
134
|
-
hasNextPage: pageParam
|
|
134
|
+
hasNextPage: hasValue(pageParam),
|
|
135
135
|
}
|
|
136
136
|
: {
|
|
137
137
|
isWaiting: false,
|
|
@@ -142,7 +142,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
142
142
|
errorUpdatedAt,
|
|
143
143
|
isGoingToRetry: shouldRetry,
|
|
144
144
|
pageParam,
|
|
145
|
-
hasNextPage: pageParam
|
|
145
|
+
hasNextPage: hasValue(pageParam),
|
|
146
146
|
});
|
|
147
147
|
if (shouldRetry) {
|
|
148
148
|
retryTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
@@ -184,7 +184,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
184
184
|
data: select(response, { key, data }),
|
|
185
185
|
pageParam: newPageParam,
|
|
186
186
|
pageParams: pageParams.concat(newPageParam),
|
|
187
|
-
hasNextPage: newPageParam
|
|
187
|
+
hasNextPage: hasValue(newPageParam),
|
|
188
188
|
});
|
|
189
189
|
})
|
|
190
190
|
.catch((error) => {
|
|
@@ -287,7 +287,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
287
287
|
data: select(response, { key: key, data: null }),
|
|
288
288
|
pageParam: newPageParam,
|
|
289
289
|
pageParams: [undefined, newPageParam],
|
|
290
|
-
hasNextPage: newPageParam
|
|
290
|
+
hasNextPage: hasValue(newPageParam),
|
|
291
291
|
});
|
|
292
292
|
});
|
|
293
293
|
};
|
|
@@ -39,6 +39,10 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
39
39
|
};
|
|
40
40
|
export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = InitStoreOptions<T> & {
|
|
41
41
|
onBeforeChangeKey?: (nextKey: TKey, prevKey: TKey) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Will be triggered when a single store with a specific key was initialized.
|
|
44
|
+
*/
|
|
45
|
+
onStoreInitialized?: (key: TKey, keyHash: string) => void;
|
|
42
46
|
defaultDeps?: SelectDeps<T>;
|
|
43
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
44
48
|
};
|
|
@@ -2,13 +2,14 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
2
2
|
import { hashStoreKey, noop } from '../utils';
|
|
3
3
|
import { initStore, } from '../vanilla';
|
|
4
4
|
export const createStores = (initializer, options = {}) => {
|
|
5
|
-
const { onBeforeChangeKey = noop, defaultDeps, hashKeyFn = hashStoreKey } = options;
|
|
5
|
+
const { onBeforeChangeKey = noop, onStoreInitialized = noop, defaultDeps, hashKeyFn = hashStoreKey, } = options;
|
|
6
6
|
const stores = new Map();
|
|
7
7
|
const getStore = (_key) => {
|
|
8
8
|
const key = _key || {};
|
|
9
9
|
const keyHash = hashKeyFn(key);
|
|
10
10
|
if (!stores.has(keyHash)) {
|
|
11
11
|
stores.set(keyHash, initStore((api) => initializer({ key, keyHash, ...api }), options));
|
|
12
|
+
onStoreInitialized(key, keyHash);
|
|
12
13
|
}
|
|
13
14
|
return stores.get(keyHash);
|
|
14
15
|
};
|
package/esm/utils/index.d.ts
CHANGED
package/esm/utils/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export const noop = () => { };
|
|
2
|
-
export const identityFn = (
|
|
2
|
+
export const identityFn = (value) => value;
|
|
3
|
+
export const hasValue = (value) => value !== undefined && value !== null;
|
|
3
4
|
export const hashStoreKey = (obj) => JSON.stringify(obj, Object.keys(obj).sort());
|
|
@@ -87,7 +87,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
87
87
|
responseAllPages.push(response);
|
|
88
88
|
const newPageParam = getNextPageParam(response, responseAllPages.length);
|
|
89
89
|
newPageParams.push(newPageParam);
|
|
90
|
-
if (newPageParam
|
|
90
|
+
if ((0, utils_1.hasValue)(newPageParam) && newPageParams.length < pageParams.length) {
|
|
91
91
|
pageParam = newPageParam;
|
|
92
92
|
callQuery();
|
|
93
93
|
return;
|
|
@@ -112,7 +112,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
112
112
|
retryCount: 0,
|
|
113
113
|
pageParam: newPageParam,
|
|
114
114
|
pageParams: newPageParams,
|
|
115
|
-
hasNextPage: newPageParam
|
|
115
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
116
116
|
});
|
|
117
117
|
onSuccess(response, stateBeforeCallQuery);
|
|
118
118
|
})
|
|
@@ -134,7 +134,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
134
134
|
errorUpdatedAt,
|
|
135
135
|
isGoingToRetry: shouldRetry,
|
|
136
136
|
pageParam,
|
|
137
|
-
hasNextPage: pageParam
|
|
137
|
+
hasNextPage: (0, utils_1.hasValue)(pageParam),
|
|
138
138
|
}
|
|
139
139
|
: {
|
|
140
140
|
isWaiting: false,
|
|
@@ -145,7 +145,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
145
145
|
errorUpdatedAt,
|
|
146
146
|
isGoingToRetry: shouldRetry,
|
|
147
147
|
pageParam,
|
|
148
|
-
hasNextPage: pageParam
|
|
148
|
+
hasNextPage: (0, utils_1.hasValue)(pageParam),
|
|
149
149
|
});
|
|
150
150
|
if (shouldRetry) {
|
|
151
151
|
retryTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
@@ -187,7 +187,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
187
187
|
data: select(response, { key, data }),
|
|
188
188
|
pageParam: newPageParam,
|
|
189
189
|
pageParams: pageParams.concat(newPageParam),
|
|
190
|
-
hasNextPage: newPageParam
|
|
190
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
191
191
|
});
|
|
192
192
|
})
|
|
193
193
|
.catch((error) => {
|
|
@@ -290,7 +290,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
290
290
|
data: select(response, { key: key, data: null }),
|
|
291
291
|
pageParam: newPageParam,
|
|
292
292
|
pageParams: [undefined, newPageParam],
|
|
293
|
-
hasNextPage: newPageParam
|
|
293
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
};
|
|
@@ -39,6 +39,10 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
39
39
|
};
|
|
40
40
|
export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = InitStoreOptions<T> & {
|
|
41
41
|
onBeforeChangeKey?: (nextKey: TKey, prevKey: TKey) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Will be triggered when a single store with a specific key was initialized.
|
|
44
|
+
*/
|
|
45
|
+
onStoreInitialized?: (key: TKey, keyHash: string) => void;
|
|
42
46
|
defaultDeps?: SelectDeps<T>;
|
|
43
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
44
48
|
};
|
|
@@ -5,13 +5,14 @@ const hooks_1 = require("preact/hooks");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const vanilla_1 = require("../vanilla");
|
|
7
7
|
const createStores = (initializer, options = {}) => {
|
|
8
|
-
const { onBeforeChangeKey = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey } = options;
|
|
8
|
+
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey, } = options;
|
|
9
9
|
const stores = new Map();
|
|
10
10
|
const getStore = (_key) => {
|
|
11
11
|
const key = _key || {};
|
|
12
12
|
const keyHash = hashKeyFn(key);
|
|
13
13
|
if (!stores.has(keyHash)) {
|
|
14
14
|
stores.set(keyHash, (0, vanilla_1.initStore)((api) => initializer({ key, keyHash, ...api }), options));
|
|
15
|
+
onStoreInitialized(key, keyHash);
|
|
15
16
|
}
|
|
16
17
|
return stores.get(keyHash);
|
|
17
18
|
};
|
|
@@ -87,7 +87,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
87
87
|
responseAllPages.push(response);
|
|
88
88
|
const newPageParam = getNextPageParam(response, responseAllPages.length);
|
|
89
89
|
newPageParams.push(newPageParam);
|
|
90
|
-
if (newPageParam
|
|
90
|
+
if ((0, utils_1.hasValue)(newPageParam) && newPageParams.length < pageParams.length) {
|
|
91
91
|
pageParam = newPageParam;
|
|
92
92
|
callQuery();
|
|
93
93
|
return;
|
|
@@ -112,7 +112,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
112
112
|
retryCount: 0,
|
|
113
113
|
pageParam: newPageParam,
|
|
114
114
|
pageParams: newPageParams,
|
|
115
|
-
hasNextPage: newPageParam
|
|
115
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
116
116
|
});
|
|
117
117
|
onSuccess(response, stateBeforeCallQuery);
|
|
118
118
|
})
|
|
@@ -134,7 +134,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
134
134
|
errorUpdatedAt,
|
|
135
135
|
isGoingToRetry: shouldRetry,
|
|
136
136
|
pageParam,
|
|
137
|
-
hasNextPage: pageParam
|
|
137
|
+
hasNextPage: (0, utils_1.hasValue)(pageParam),
|
|
138
138
|
}
|
|
139
139
|
: {
|
|
140
140
|
isWaiting: false,
|
|
@@ -145,7 +145,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
145
145
|
errorUpdatedAt,
|
|
146
146
|
isGoingToRetry: shouldRetry,
|
|
147
147
|
pageParam,
|
|
148
|
-
hasNextPage: pageParam
|
|
148
|
+
hasNextPage: (0, utils_1.hasValue)(pageParam),
|
|
149
149
|
});
|
|
150
150
|
if (shouldRetry) {
|
|
151
151
|
retryTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
@@ -187,7 +187,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
187
187
|
data: select(response, { key, data }),
|
|
188
188
|
pageParam: newPageParam,
|
|
189
189
|
pageParams: pageParams.concat(newPageParam),
|
|
190
|
-
hasNextPage: newPageParam
|
|
190
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
191
191
|
});
|
|
192
192
|
})
|
|
193
193
|
.catch((error) => {
|
|
@@ -290,7 +290,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
290
290
|
data: select(response, { key: key, data: null }),
|
|
291
291
|
pageParam: newPageParam,
|
|
292
292
|
pageParams: [undefined, newPageParam],
|
|
293
|
-
hasNextPage: newPageParam
|
|
293
|
+
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
};
|
|
@@ -39,6 +39,10 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
39
39
|
};
|
|
40
40
|
export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = InitStoreOptions<T> & {
|
|
41
41
|
onBeforeChangeKey?: (nextKey: TKey, prevKey: TKey) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Will be triggered when a single store with a specific key was initialized.
|
|
44
|
+
*/
|
|
45
|
+
onStoreInitialized?: (key: TKey, keyHash: string) => void;
|
|
42
46
|
defaultDeps?: SelectDeps<T>;
|
|
43
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
44
48
|
};
|
|
@@ -5,13 +5,14 @@ const react_1 = require("react");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const vanilla_1 = require("../vanilla");
|
|
7
7
|
const createStores = (initializer, options = {}) => {
|
|
8
|
-
const { onBeforeChangeKey = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey } = options;
|
|
8
|
+
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey, } = options;
|
|
9
9
|
const stores = new Map();
|
|
10
10
|
const getStore = (_key) => {
|
|
11
11
|
const key = _key || {};
|
|
12
12
|
const keyHash = hashKeyFn(key);
|
|
13
13
|
if (!stores.has(keyHash)) {
|
|
14
14
|
stores.set(keyHash, (0, vanilla_1.initStore)((api) => initializer({ key, keyHash, ...api }), options));
|
|
15
|
+
onStoreInitialized(key, keyHash);
|
|
15
16
|
}
|
|
16
17
|
return stores.get(keyHash);
|
|
17
18
|
};
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hashStoreKey = exports.identityFn = exports.noop = void 0;
|
|
3
|
+
exports.hashStoreKey = exports.hasValue = exports.identityFn = exports.noop = void 0;
|
|
4
4
|
const noop = () => { };
|
|
5
5
|
exports.noop = noop;
|
|
6
|
-
const identityFn = (
|
|
6
|
+
const identityFn = (value) => value;
|
|
7
7
|
exports.identityFn = identityFn;
|
|
8
|
+
const hasValue = (value) => value !== undefined && value !== null;
|
|
9
|
+
exports.hasValue = hasValue;
|
|
8
10
|
const hashStoreKey = (obj) => JSON.stringify(obj, Object.keys(obj).sort());
|
|
9
11
|
exports.hashStoreKey = hashStoreKey;
|