@pinia/colada-plugin-delay 0.1.4 → 0.1.5
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.d.mts +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -16
- package/dist/index.cjs +0 -52
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -33
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { ShallowRef } from "vue";
|
|
|
2
2
|
import { PiniaColadaPlugin } from "@pinia/colada";
|
|
3
3
|
|
|
4
4
|
//#region src/delay.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Options for the {@link PiniaColadaDelay} plugin.
|
|
8
7
|
*/
|
|
@@ -21,7 +20,7 @@ declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColad
|
|
|
21
20
|
declare module '@pinia/colada' {
|
|
22
21
|
interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {}
|
|
23
22
|
interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {}
|
|
24
|
-
interface UseQueryEntryExtensions<TData, TError> {
|
|
23
|
+
interface UseQueryEntryExtensions<TData, TError, TDataInitial> {
|
|
25
24
|
/**
|
|
26
25
|
* Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
|
|
27
26
|
*/
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/delay.ts"],"sourcesContent":["/**\n * Pinia Colada Delay Loading plugin.\n *\n * Allows delaying the `loading` value for `asyncStatus` to improve _perceived performance_.\n *\n * @module @pinia/colada-plugin-delay\n */\n\nimport type { ShallowRef } from 'vue'\nimport { customRef, shallowRef } from 'vue'\nimport type { PiniaColadaPlugin, AsyncStatus } from '@pinia/colada'\n\n/**\n * Options for the {@link PiniaColadaDelay} plugin.\n */\ninterface PiniaColadaDelayOptions {\n /**\n * Delay in milliseconds to wait before letting the `asyncStatus` become `'loading'`. Set to `false` or 0 to disable. Requires the {@link PiniaColadaDelay} plugin.\n * @default 200\n */\n delay?: number | false\n}\n\n/**\n * Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.\n * @param options - Pinia Colada Delay Loading plugin options\n */\nexport function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin {\n return ({ queryCache, scope }) => {\n queryCache.$onAction(({ name, args }) => {\n if (name === 'extend') {\n const [entry] = args\n const delay = entry.options?.delay ?? options?.delay ?? 200\n scope.run(() => {\n const isDelaying = shallowRef(false)\n entry.ext.isDelaying = isDelaying\n if (!delay) return\n\n const initialValue = entry.asyncStatus.value\n entry.asyncStatus = customRef<AsyncStatus>((track, trigger) => {\n let value = initialValue\n let timeout: ReturnType<typeof setTimeout> | undefined\n return {\n get() {\n track()\n return value\n },\n set(newValue) {\n clearTimeout(timeout)\n if (newValue === 'loading') {\n isDelaying.value = true\n timeout = setTimeout(() => {\n isDelaying.value = false\n value = newValue\n trigger()\n }, delay)\n } else {\n isDelaying.value = false\n value = newValue\n trigger()\n }\n },\n }\n })\n })\n }\n })\n }\n}\n\ndeclare module '@pinia/colada' {\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {}\n\n interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {}\n\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryEntryExtensions<TData, TError, TDataInitial> {\n /**\n * Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.\n */\n isDelaying: ShallowRef<boolean>\n }\n}\n"],"mappings":";;;;;;;AA2BA,SAAgB,iBAAiB,SAAsD;AACrF,SAAQ,EAAE,YAAY,YAAY;AAChC,aAAW,WAAW,EAAE,MAAM,WAAW;AACvC,OAAI,SAAS,UAAU;IACrB,MAAM,CAAC,SAAS;IAChB,MAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,UAAM,UAAU;KACd,MAAM,aAAa,WAAW,MAAM;AACpC,WAAM,IAAI,aAAa;AACvB,SAAI,CAAC,MAAO;KAEZ,MAAM,eAAe,MAAM,YAAY;AACvC,WAAM,cAAc,WAAwB,OAAO,YAAY;MAC7D,IAAI,QAAQ;MACZ,IAAI;AACJ,aAAO;OACL,MAAM;AACJ,eAAO;AACP,eAAO;;OAET,IAAI,UAAU;AACZ,qBAAa,QAAQ;AACrB,YAAI,aAAa,WAAW;AAC1B,oBAAW,QAAQ;AACnB,mBAAU,iBAAiB;AACzB,qBAAW,QAAQ;AACnB,kBAAQ;AACR,mBAAS;YACR,MAAM;eACJ;AACL,oBAAW,QAAQ;AACnB,iBAAQ;AACR,kBAAS;;;OAGd;OACD;MACF;;IAEJ"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.5",
|
|
8
8
|
"description": "Delay async status in Pinia Colada",
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Eduardo San Martin Morote",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"funding": "https://github.com/sponsors/posva",
|
|
15
|
-
"homepage": "https://github.com/posva/pinia-colada/plugins/delay
|
|
15
|
+
"homepage": "https://github.com/posva/pinia-colada/blob/main/plugins/delay/README.md",
|
|
16
16
|
"repository": "posva/pinia-colada",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/posva/pinia-colada/issues"
|
|
@@ -29,18 +29,8 @@
|
|
|
29
29
|
"delay"
|
|
30
30
|
],
|
|
31
31
|
"sideEffects": false,
|
|
32
|
-
"exports":
|
|
33
|
-
|
|
34
|
-
"types": {
|
|
35
|
-
"import": "./dist/index.d.mts",
|
|
36
|
-
"require": "./dist/index.d.cts"
|
|
37
|
-
},
|
|
38
|
-
"import": "./dist/index.mjs",
|
|
39
|
-
"require": "./dist/index.cjs"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"main": "./dist/index.cjs",
|
|
43
|
-
"module": "./dist/index.mjs",
|
|
32
|
+
"exports": "./dist/index.mjs",
|
|
33
|
+
"main": "./dist/index.mjs",
|
|
44
34
|
"types": "./dist/index.d.mts",
|
|
45
35
|
"typesVersions": {
|
|
46
36
|
"*": {
|
|
@@ -56,10 +46,10 @@
|
|
|
56
46
|
"dist"
|
|
57
47
|
],
|
|
58
48
|
"peerDependencies": {
|
|
59
|
-
"@pinia/colada": ">=0.
|
|
49
|
+
"@pinia/colada": ">=0.21.5"
|
|
60
50
|
},
|
|
61
51
|
"devDependencies": {
|
|
62
|
-
"@pinia/colada": "^0.
|
|
52
|
+
"@pinia/colada": "^0.21.5"
|
|
63
53
|
},
|
|
64
54
|
"scripts": {
|
|
65
55
|
"build": "tsdown",
|
package/dist/index.cjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
let vue = require("vue");
|
|
2
|
-
|
|
3
|
-
//#region src/delay.ts
|
|
4
|
-
/**
|
|
5
|
-
* Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.
|
|
6
|
-
* @param options - Pinia Colada Delay Loading plugin options
|
|
7
|
-
*/
|
|
8
|
-
function PiniaColadaDelay(options) {
|
|
9
|
-
return ({ queryCache, scope }) => {
|
|
10
|
-
queryCache.$onAction(({ name, args }) => {
|
|
11
|
-
if (name === "extend") {
|
|
12
|
-
const [entry] = args;
|
|
13
|
-
const delay = entry.options?.delay ?? options?.delay ?? 200;
|
|
14
|
-
scope.run(() => {
|
|
15
|
-
const isDelaying = (0, vue.shallowRef)(false);
|
|
16
|
-
entry.ext.isDelaying = isDelaying;
|
|
17
|
-
if (!delay) return;
|
|
18
|
-
const initialValue = entry.asyncStatus.value;
|
|
19
|
-
entry.asyncStatus = (0, vue.customRef)((track, trigger) => {
|
|
20
|
-
let value = initialValue;
|
|
21
|
-
let timeout;
|
|
22
|
-
return {
|
|
23
|
-
get() {
|
|
24
|
-
track();
|
|
25
|
-
return value;
|
|
26
|
-
},
|
|
27
|
-
set(newValue) {
|
|
28
|
-
clearTimeout(timeout);
|
|
29
|
-
if (newValue === "loading") {
|
|
30
|
-
isDelaying.value = true;
|
|
31
|
-
timeout = setTimeout(() => {
|
|
32
|
-
isDelaying.value = false;
|
|
33
|
-
value = newValue;
|
|
34
|
-
trigger();
|
|
35
|
-
}, delay);
|
|
36
|
-
} else {
|
|
37
|
-
isDelaying.value = false;
|
|
38
|
-
value = newValue;
|
|
39
|
-
trigger();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
exports.PiniaColadaDelay = PiniaColadaDelay;
|
|
52
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["timeout: ReturnType<typeof setTimeout> | undefined"],"sources":["../src/delay.ts"],"sourcesContent":["/**\n * Pinia Colada Delay Loading plugin.\n *\n * Allows delaying the `loading` value for `asyncStatus` to improve _perceived performance_.\n *\n * @module @pinia/colada-plugin-delay\n */\n\nimport type { ShallowRef } from 'vue'\nimport { customRef, shallowRef } from 'vue'\nimport type { PiniaColadaPlugin, AsyncStatus } from '@pinia/colada'\n\n/**\n * Options for the {@link PiniaColadaDelay} plugin.\n */\ninterface PiniaColadaDelayOptions {\n /**\n * Delay in milliseconds to wait before letting the `asyncStatus` become `'loading'`. Set to `false` or 0 to disable. Requires the {@link PiniaColadaDelay} plugin.\n * @default 200\n */\n delay?: number | false\n}\n\n/**\n * Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.\n * @param options - Pinia Colada Delay Loading plugin options\n */\nexport function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin {\n return ({ queryCache, scope }) => {\n queryCache.$onAction(({ name, args }) => {\n if (name === 'extend') {\n const [entry] = args\n const delay = entry.options?.delay ?? options?.delay ?? 200\n scope.run(() => {\n const isDelaying = shallowRef(false)\n entry.ext.isDelaying = isDelaying\n if (!delay) return\n\n const initialValue = entry.asyncStatus.value\n entry.asyncStatus = customRef<AsyncStatus>((track, trigger) => {\n let value = initialValue\n let timeout: ReturnType<typeof setTimeout> | undefined\n return {\n get() {\n track()\n return value\n },\n set(newValue) {\n clearTimeout(timeout)\n if (newValue === 'loading') {\n isDelaying.value = true\n timeout = setTimeout(() => {\n isDelaying.value = false\n value = newValue\n trigger()\n }, delay)\n } else {\n isDelaying.value = false\n value = newValue\n trigger()\n }\n },\n }\n })\n })\n }\n })\n }\n}\n\ndeclare module '@pinia/colada' {\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {}\n\n interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {}\n\n interface UseQueryEntryExtensions<\n TData,\n // eslint-disable-next-line unused-imports/no-unused-vars\n TError,\n > {\n /**\n * Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.\n */\n isDelaying: ShallowRef<boolean>\n }\n}\n"],"mappings":";;;;;;;AA2BA,SAAgB,iBAAiB,SAAsD;AACrF,SAAQ,EAAE,YAAY,YAAY;AAChC,aAAW,WAAW,EAAE,MAAM,WAAW;AACvC,OAAI,SAAS,UAAU;IACrB,MAAM,CAAC,SAAS;IAChB,MAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,UAAM,UAAU;KACd,MAAM,iCAAwB,MAAM;AACpC,WAAM,IAAI,aAAa;AACvB,SAAI,CAAC,MAAO;KAEZ,MAAM,eAAe,MAAM,YAAY;AACvC,WAAM,kCAAsC,OAAO,YAAY;MAC7D,IAAI,QAAQ;MACZ,IAAIA;AACJ,aAAO;OACL,MAAM;AACJ,eAAO;AACP,eAAO;;OAET,IAAI,UAAU;AACZ,qBAAa,QAAQ;AACrB,YAAI,aAAa,WAAW;AAC1B,oBAAW,QAAQ;AACnB,mBAAU,iBAAiB;AACzB,qBAAW,QAAQ;AACnB,kBAAQ;AACR,mBAAS;YACR,MAAM;eACJ;AACL,oBAAW,QAAQ;AACnB,iBAAQ;AACR,kBAAS;;;OAGd;OACD;MACF;;IAEJ"}
|
package/dist/index.d.cts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ShallowRef } from "vue";
|
|
2
|
-
import { PiniaColadaPlugin } from "@pinia/colada";
|
|
3
|
-
|
|
4
|
-
//#region src/delay.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for the {@link PiniaColadaDelay} plugin.
|
|
8
|
-
*/
|
|
9
|
-
interface PiniaColadaDelayOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Delay in milliseconds to wait before letting the `asyncStatus` become `'loading'`. Set to `false` or 0 to disable. Requires the {@link PiniaColadaDelay} plugin.
|
|
12
|
-
* @default 200
|
|
13
|
-
*/
|
|
14
|
-
delay?: number | false;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.
|
|
18
|
-
* @param options - Pinia Colada Delay Loading plugin options
|
|
19
|
-
*/
|
|
20
|
-
declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin;
|
|
21
|
-
declare module '@pinia/colada' {
|
|
22
|
-
interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {}
|
|
23
|
-
interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {}
|
|
24
|
-
interface UseQueryEntryExtensions<TData, TError> {
|
|
25
|
-
/**
|
|
26
|
-
* Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
|
|
27
|
-
*/
|
|
28
|
-
isDelaying: ShallowRef<boolean>;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { PiniaColadaDelay };
|
|
33
|
-
//# sourceMappingURL=index.d.cts.map
|