@pinia/colada-plugin-delay 0.0.0 → 0.0.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/dist/index.cjs +28 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +29 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -24,35 +24,41 @@ __export(src_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(src_exports);
|
|
25
25
|
var import_vue = require("vue");
|
|
26
26
|
function PiniaColadaDelay(options) {
|
|
27
|
-
return ({ queryCache }) => {
|
|
27
|
+
return ({ queryCache, scope }) => {
|
|
28
28
|
queryCache.$onAction(({ name, after }) => {
|
|
29
29
|
if (name === "create") {
|
|
30
30
|
after((entry) => {
|
|
31
31
|
const delay = entry.options?.delay ?? options?.delay ?? 200;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
timeout
|
|
32
|
+
scope.run(() => {
|
|
33
|
+
const isDelaying = (0, import_vue.shallowRef)(false);
|
|
34
|
+
entry.ext.isDelaying = isDelaying;
|
|
35
|
+
if (!delay) return;
|
|
36
|
+
const initialValue = entry.asyncStatus.value;
|
|
37
|
+
entry.asyncStatus = (0, import_vue.customRef)((track, trigger) => {
|
|
38
|
+
let value = initialValue;
|
|
39
|
+
let timeout;
|
|
40
|
+
return {
|
|
41
|
+
get() {
|
|
42
|
+
track();
|
|
43
|
+
return value;
|
|
44
|
+
},
|
|
45
|
+
set(newValue) {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
if (newValue === "loading") {
|
|
48
|
+
isDelaying.value = true;
|
|
49
|
+
timeout = setTimeout(() => {
|
|
50
|
+
isDelaying.value = false;
|
|
51
|
+
value = newValue;
|
|
52
|
+
trigger();
|
|
53
|
+
}, delay);
|
|
54
|
+
} else {
|
|
55
|
+
isDelaying.value = false;
|
|
47
56
|
value = newValue;
|
|
48
57
|
trigger();
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
value = newValue;
|
|
52
|
-
trigger();
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
60
|
+
};
|
|
61
|
+
});
|
|
56
62
|
});
|
|
57
63
|
});
|
|
58
64
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @module @pinia/colada/plugins/delay\n */\nimport { customRef } 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 }) => {\n queryCache.$onAction(({ name, after }) => {\n if (name === 'create') {\n after((entry) => {\n const delay = entry.options?.delay ?? options?.delay ?? 200\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @module @pinia/colada/plugins/delay\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, after }) => {\n if (name === 'create') {\n after((entry) => {\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}\n\ndeclare module '@pinia/colada' {\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {}\n\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryEntryExtensions<TResult, TError> {\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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAsC;AAkB/B,SAAS,iBAAiB,SAAsD;AACrF,SAAO,CAAC,EAAE,YAAY,MAAM,MAAM;AAChC,eAAW,UAAU,CAAC,EAAE,MAAM,MAAM,MAAM;AACxC,UAAI,SAAS,UAAU;AACrB,cAAM,CAAC,UAAU;AACf,gBAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,gBAAM,IAAI,MAAM;AACd,kBAAM,iBAAa,uBAAW,KAAK;AACnC,kBAAM,IAAI,aAAa;AACvB,gBAAI,CAAC,MAAO;AAEZ,kBAAM,eAAe,MAAM,YAAY;AACvC,kBAAM,kBAAc,sBAAuB,CAAC,OAAO,YAAY;AAC7D,kBAAI,QAAQ;AACZ,kBAAI;AACJ,qBAAO;AAAA,gBACL,MAAM;AACJ,wBAAM;AACN,yBAAO;AAAA,gBACT;AAAA,gBACA,IAAI,UAAU;AACZ,+BAAa,OAAO;AACpB,sBAAI,aAAa,WAAW;AAC1B,+BAAW,QAAQ;AACnB,8BAAU,WAAW,MAAM;AACzB,iCAAW,QAAQ;AACnB,8BAAQ;AACR,8BAAQ;AAAA,oBACV,GAAG,KAAK;AAAA,kBACV,OAAO;AACL,+BAAW,QAAQ;AACnB,4BAAQ;AACR,4BAAQ;AAAA,kBACV;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
1
2
|
import { PiniaColadaPlugin } from '@pinia/colada';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @module @pinia/colada/plugins/delay
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Options for the {@link PiniaColadaDelay} plugin.
|
|
5
10
|
*/
|
|
@@ -18,6 +23,12 @@ declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColad
|
|
|
18
23
|
declare module '@pinia/colada' {
|
|
19
24
|
interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {
|
|
20
25
|
}
|
|
26
|
+
interface UseQueryEntryExtensions<TResult, TError> {
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
|
|
29
|
+
*/
|
|
30
|
+
isDelaying: ShallowRef<boolean>;
|
|
31
|
+
}
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
export { PiniaColadaDelay };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
1
2
|
import { PiniaColadaPlugin } from '@pinia/colada';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @module @pinia/colada/plugins/delay
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Options for the {@link PiniaColadaDelay} plugin.
|
|
5
10
|
*/
|
|
@@ -18,6 +23,12 @@ declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColad
|
|
|
18
23
|
declare module '@pinia/colada' {
|
|
19
24
|
interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {
|
|
20
25
|
}
|
|
26
|
+
interface UseQueryEntryExtensions<TResult, TError> {
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
|
|
29
|
+
*/
|
|
30
|
+
isDelaying: ShallowRef<boolean>;
|
|
31
|
+
}
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
export { PiniaColadaDelay };
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { customRef } from "vue";
|
|
2
|
+
import { customRef, shallowRef } from "vue";
|
|
3
3
|
function PiniaColadaDelay(options) {
|
|
4
|
-
return ({ queryCache }) => {
|
|
4
|
+
return ({ queryCache, scope }) => {
|
|
5
5
|
queryCache.$onAction(({ name, after }) => {
|
|
6
6
|
if (name === "create") {
|
|
7
7
|
after((entry) => {
|
|
8
8
|
const delay = entry.options?.delay ?? options?.delay ?? 200;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
timeout
|
|
9
|
+
scope.run(() => {
|
|
10
|
+
const isDelaying = shallowRef(false);
|
|
11
|
+
entry.ext.isDelaying = isDelaying;
|
|
12
|
+
if (!delay) return;
|
|
13
|
+
const initialValue = entry.asyncStatus.value;
|
|
14
|
+
entry.asyncStatus = customRef((track, trigger) => {
|
|
15
|
+
let value = initialValue;
|
|
16
|
+
let timeout;
|
|
17
|
+
return {
|
|
18
|
+
get() {
|
|
19
|
+
track();
|
|
20
|
+
return value;
|
|
21
|
+
},
|
|
22
|
+
set(newValue) {
|
|
23
|
+
clearTimeout(timeout);
|
|
24
|
+
if (newValue === "loading") {
|
|
25
|
+
isDelaying.value = true;
|
|
26
|
+
timeout = setTimeout(() => {
|
|
27
|
+
isDelaying.value = false;
|
|
28
|
+
value = newValue;
|
|
29
|
+
trigger();
|
|
30
|
+
}, delay);
|
|
31
|
+
} else {
|
|
32
|
+
isDelaying.value = false;
|
|
24
33
|
value = newValue;
|
|
25
34
|
trigger();
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
value = newValue;
|
|
29
|
-
trigger();
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
37
|
+
};
|
|
38
|
+
});
|
|
33
39
|
});
|
|
34
40
|
});
|
|
35
41
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @module @pinia/colada/plugins/delay\n */\nimport { customRef } 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 }) => {\n queryCache.$onAction(({ name, after }) => {\n if (name === 'create') {\n after((entry) => {\n const delay = entry.options?.delay ?? options?.delay ?? 200\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @module @pinia/colada/plugins/delay\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, after }) => {\n if (name === 'create') {\n after((entry) => {\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}\n\ndeclare module '@pinia/colada' {\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {}\n\n // eslint-disable-next-line unused-imports/no-unused-vars\n interface UseQueryEntryExtensions<TResult, TError> {\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":";AAIA,SAAS,WAAW,kBAAkB;AAkB/B,SAAS,iBAAiB,SAAsD;AACrF,SAAO,CAAC,EAAE,YAAY,MAAM,MAAM;AAChC,eAAW,UAAU,CAAC,EAAE,MAAM,MAAM,MAAM;AACxC,UAAI,SAAS,UAAU;AACrB,cAAM,CAAC,UAAU;AACf,gBAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,gBAAM,IAAI,MAAM;AACd,kBAAM,aAAa,WAAW,KAAK;AACnC,kBAAM,IAAI,aAAa;AACvB,gBAAI,CAAC,MAAO;AAEZ,kBAAM,eAAe,MAAM,YAAY;AACvC,kBAAM,cAAc,UAAuB,CAAC,OAAO,YAAY;AAC7D,kBAAI,QAAQ;AACZ,kBAAI;AACJ,qBAAO;AAAA,gBACL,MAAM;AACJ,wBAAM;AACN,yBAAO;AAAA,gBACT;AAAA,gBACA,IAAI,UAAU;AACZ,+BAAa,OAAO;AACpB,sBAAI,aAAa,WAAW;AAC1B,+BAAW,QAAQ;AACnB,8BAAU,WAAW,MAAM;AACzB,iCAAW,QAAQ;AACnB,8BAAQ;AACR,8BAAQ;AAAA,oBACV,GAAG,KAAK;AAAA,kBACV,OAAO;AACL,+BAAW,QAAQ;AACnB,4BAAQ;AACR,4BAAQ;AAAA,kBACV;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.1",
|
|
8
8
|
"description": "Delay async status in Pinia Colada",
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Eduardo San Martin Morote",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"dist"
|
|
60
60
|
],
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@pinia/colada": "^0.
|
|
62
|
+
"@pinia/colada": "^0.12.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@pinia/colada": "^0.
|
|
65
|
+
"@pinia/colada": "^0.12.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsup",
|