@pinia/colada-plugin-delay 0.0.0
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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Eduardo San Martin Morote
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<h1>
|
|
2
|
+
<img height="76" src="https://github.com/posva/pinia-colada/assets/664177/02011637-f94d-4a35-854a-02f7aed86a3c" alt="Pinia Colada logo">
|
|
3
|
+
Pinia Colada Delay
|
|
4
|
+
</h1>
|
|
5
|
+
|
|
6
|
+
<a href="https://npmjs.com/package/@pinia/colada-plugin-delay">
|
|
7
|
+
<img src="https://badgen.net/npm/v/@pinia/colada-plugin-delay/latest" alt="npm package">
|
|
8
|
+
</a>
|
|
9
|
+
|
|
10
|
+
Delay the `asyncStatus` of a query to avoid flickering when refreshing data. The perfect addition to `placeholderData` in your paginated queries 💪.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @pinia/colada-plugin-delay
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { PiniaColadaDelay } from '@pinia/colada-plugin-delay'
|
|
22
|
+
|
|
23
|
+
// Pass the plugin to Pinia Colada options
|
|
24
|
+
app.use(PiniaColada, {
|
|
25
|
+
// ...
|
|
26
|
+
plugins: [
|
|
27
|
+
PiniaColadaDelay({
|
|
28
|
+
delay: 200, // default delay
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
You can customize the delay behavior individually for each query with the `delay` option:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
useQuery({
|
|
38
|
+
key: ['todos'],
|
|
39
|
+
query: getTodos,
|
|
40
|
+
delay: false, // disable delay
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
[MIT](http://opensource.org/licenses/MIT)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
PiniaColadaDelay: () => PiniaColadaDelay
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
var import_vue = require("vue");
|
|
26
|
+
function PiniaColadaDelay(options) {
|
|
27
|
+
return ({ queryCache }) => {
|
|
28
|
+
queryCache.$onAction(({ name, after }) => {
|
|
29
|
+
if (name === "create") {
|
|
30
|
+
after((entry) => {
|
|
31
|
+
const delay = entry.options?.delay ?? options?.delay ?? 200;
|
|
32
|
+
console.log("delay", entry.options?.delay, options?.delay, delay);
|
|
33
|
+
if (!delay) return;
|
|
34
|
+
const initialValue = entry.asyncStatus.value;
|
|
35
|
+
entry.asyncStatus = (0, import_vue.customRef)((track, trigger) => {
|
|
36
|
+
let value = initialValue;
|
|
37
|
+
let timeout;
|
|
38
|
+
return {
|
|
39
|
+
get() {
|
|
40
|
+
track();
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
set(newValue) {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
if (newValue === "loading") {
|
|
46
|
+
timeout = setTimeout(() => {
|
|
47
|
+
value = newValue;
|
|
48
|
+
trigger();
|
|
49
|
+
}, delay);
|
|
50
|
+
} else {
|
|
51
|
+
value = newValue;
|
|
52
|
+
trigger();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
PiniaColadaDelay
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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 console.log('delay', entry.options?.delay, options?.delay, delay)\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 timeout = setTimeout(() => {\n value = newValue\n trigger()\n }, delay)\n } else {\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 export interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAkBnB,SAAS,iBAAiB,SAAsD;AACrF,SAAO,CAAC,EAAE,WAAW,MAAM;AACzB,eAAW,UAAU,CAAC,EAAE,MAAM,MAAM,MAAM;AACxC,UAAI,SAAS,UAAU;AACrB,cAAM,CAAC,UAAU;AACf,gBAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,kBAAQ,IAAI,SAAS,MAAM,SAAS,OAAO,SAAS,OAAO,KAAK;AAChE,cAAI,CAAC,MAAO;AAEZ,gBAAM,eAAe,MAAM,YAAY;AACvC,gBAAM,kBAAc,sBAAuB,CAAC,OAAO,YAAY;AAC7D,gBAAI,QAAQ;AACZ,gBAAI;AACJ,mBAAO;AAAA,cACL,MAAM;AACJ,sBAAM;AACN,uBAAO;AAAA,cACT;AAAA,cACA,IAAI,UAAU;AACZ,6BAAa,OAAO;AACpB,oBAAI,aAAa,WAAW;AAC1B,4BAAU,WAAW,MAAM;AACzB,4BAAQ;AACR,4BAAQ;AAAA,kBACV,GAAG,KAAK;AAAA,gBACV,OAAO;AACL,0BAAQ;AACR,0BAAQ;AAAA,gBACV;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PiniaColadaPlugin } from '@pinia/colada';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for the {@link PiniaColadaDelay} plugin.
|
|
5
|
+
*/
|
|
6
|
+
interface PiniaColadaDelayOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Delay in milliseconds to wait before letting the `asyncStatus` become `'loading'`. Set to `false` or 0 to disable. Requires the {@link PiniaColadaDelay} plugin.
|
|
9
|
+
* @default 200
|
|
10
|
+
*/
|
|
11
|
+
delay?: number | false;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.
|
|
15
|
+
* @param options - Pinia Colada Delay Loading plugin options
|
|
16
|
+
*/
|
|
17
|
+
declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin;
|
|
18
|
+
declare module '@pinia/colada' {
|
|
19
|
+
interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { PiniaColadaDelay };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PiniaColadaPlugin } from '@pinia/colada';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for the {@link PiniaColadaDelay} plugin.
|
|
5
|
+
*/
|
|
6
|
+
interface PiniaColadaDelayOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Delay in milliseconds to wait before letting the `asyncStatus` become `'loading'`. Set to `false` or 0 to disable. Requires the {@link PiniaColadaDelay} plugin.
|
|
9
|
+
* @default 200
|
|
10
|
+
*/
|
|
11
|
+
delay?: number | false;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Delays the `asyncStatus` of a query by a certain amount of time to avoid flickering between refreshes.
|
|
15
|
+
* @param options - Pinia Colada Delay Loading plugin options
|
|
16
|
+
*/
|
|
17
|
+
declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin;
|
|
18
|
+
declare module '@pinia/colada' {
|
|
19
|
+
interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { PiniaColadaDelay };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { customRef } from "vue";
|
|
3
|
+
function PiniaColadaDelay(options) {
|
|
4
|
+
return ({ queryCache }) => {
|
|
5
|
+
queryCache.$onAction(({ name, after }) => {
|
|
6
|
+
if (name === "create") {
|
|
7
|
+
after((entry) => {
|
|
8
|
+
const delay = entry.options?.delay ?? options?.delay ?? 200;
|
|
9
|
+
console.log("delay", entry.options?.delay, options?.delay, delay);
|
|
10
|
+
if (!delay) return;
|
|
11
|
+
const initialValue = entry.asyncStatus.value;
|
|
12
|
+
entry.asyncStatus = customRef((track, trigger) => {
|
|
13
|
+
let value = initialValue;
|
|
14
|
+
let timeout;
|
|
15
|
+
return {
|
|
16
|
+
get() {
|
|
17
|
+
track();
|
|
18
|
+
return value;
|
|
19
|
+
},
|
|
20
|
+
set(newValue) {
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
if (newValue === "loading") {
|
|
23
|
+
timeout = setTimeout(() => {
|
|
24
|
+
value = newValue;
|
|
25
|
+
trigger();
|
|
26
|
+
}, delay);
|
|
27
|
+
} else {
|
|
28
|
+
value = newValue;
|
|
29
|
+
trigger();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
PiniaColadaDelay
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 console.log('delay', entry.options?.delay, options?.delay, delay)\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 timeout = setTimeout(() => {\n value = newValue\n trigger()\n }, delay)\n } else {\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 export interface UseQueryOptions<TResult, TError> extends PiniaColadaDelayOptions {}\n}\n"],"mappings":";AAGA,SAAS,iBAAiB;AAkBnB,SAAS,iBAAiB,SAAsD;AACrF,SAAO,CAAC,EAAE,WAAW,MAAM;AACzB,eAAW,UAAU,CAAC,EAAE,MAAM,MAAM,MAAM;AACxC,UAAI,SAAS,UAAU;AACrB,cAAM,CAAC,UAAU;AACf,gBAAM,QAAQ,MAAM,SAAS,SAAS,SAAS,SAAS;AACxD,kBAAQ,IAAI,SAAS,MAAM,SAAS,OAAO,SAAS,OAAO,KAAK;AAChE,cAAI,CAAC,MAAO;AAEZ,gBAAM,eAAe,MAAM,YAAY;AACvC,gBAAM,cAAc,UAAuB,CAAC,OAAO,YAAY;AAC7D,gBAAI,QAAQ;AACZ,gBAAI;AACJ,mBAAO;AAAA,cACL,MAAM;AACJ,sBAAM;AACN,uBAAO;AAAA,cACT;AAAA,cACA,IAAI,UAAU;AACZ,6BAAa,OAAO;AACpB,oBAAI,aAAa,WAAW;AAC1B,4BAAU,WAAW,MAAM;AACzB,4BAAQ;AACR,4BAAQ;AAAA,kBACV,GAAG,KAAK;AAAA,gBACV,OAAO;AACL,0BAAQ;AACR,0BAAQ;AAAA,gBACV;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pinia/colada-plugin-delay",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.0.0",
|
|
8
|
+
"description": "Delay async status in Pinia Colada",
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Eduardo San Martin Morote",
|
|
11
|
+
"email": "posva13@gmail.com"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"funding": "https://github.com/sponsors/posva",
|
|
15
|
+
"homepage": "https://github.com/posva/pinia-colada/plugins/delay#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/posva/pinia-colada.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/posva/pinia-colada/issues"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"pinia",
|
|
25
|
+
"plugin",
|
|
26
|
+
"data",
|
|
27
|
+
"fetching",
|
|
28
|
+
"query",
|
|
29
|
+
"mutation",
|
|
30
|
+
"cache",
|
|
31
|
+
"layer",
|
|
32
|
+
"delay"
|
|
33
|
+
],
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": {
|
|
38
|
+
"import": "./dist/index.d.ts",
|
|
39
|
+
"require": "./dist/index.d.cts"
|
|
40
|
+
},
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"require": "./dist/index.cjs"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"main": "./dist/index.cjs",
|
|
46
|
+
"module": "./dist/index.js",
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"typesVersions": {
|
|
49
|
+
"*": {
|
|
50
|
+
"*": [
|
|
51
|
+
"./dist/*",
|
|
52
|
+
"./*"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"LICENSE",
|
|
58
|
+
"README.md",
|
|
59
|
+
"dist"
|
|
60
|
+
],
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@pinia/colada": "^0.11.1"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@pinia/colada": "^0.11.1"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsup",
|
|
69
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @pinia/colada-plugin-delay -r 1",
|
|
70
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
71
|
+
}
|
|
72
|
+
}
|