@pinia/colada-plugin-delay 0.0.6 → 0.1.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.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, 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, TDataInitial> extends PiniaColadaDelayOptions {}\n\n interface UseQueryOptionsGlobal 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;AASA,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":[]}
1
+ {"version":3,"sources":["../src/index.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, 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<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> {\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;AASA,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
@@ -25,11 +25,11 @@ interface PiniaColadaDelayOptions {
25
25
  */
26
26
  declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin;
27
27
  declare module '@pinia/colada' {
28
- interface UseQueryOptions<TResult, TError, TDataInitial> extends PiniaColadaDelayOptions {
28
+ interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {
29
29
  }
30
30
  interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {
31
31
  }
32
- interface UseQueryEntryExtensions<TResult, TError> {
32
+ interface UseQueryEntryExtensions<TData, TError> {
33
33
  /**
34
34
  * Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
35
35
  */
package/dist/index.d.ts CHANGED
@@ -25,11 +25,11 @@ interface PiniaColadaDelayOptions {
25
25
  */
26
26
  declare function PiniaColadaDelay(options?: PiniaColadaDelayOptions): PiniaColadaPlugin;
27
27
  declare module '@pinia/colada' {
28
- interface UseQueryOptions<TResult, TError, TDataInitial> extends PiniaColadaDelayOptions {
28
+ interface UseQueryOptions<TData, TError, TDataInitial> extends PiniaColadaDelayOptions {
29
29
  }
30
30
  interface UseQueryOptionsGlobal extends PiniaColadaDelayOptions {
31
31
  }
32
- interface UseQueryEntryExtensions<TResult, TError> {
32
+ interface UseQueryEntryExtensions<TData, TError> {
33
33
  /**
34
34
  * Returns whether the query is currently delaying its `asyncStatus` from becoming `'loading'`. Requires the {@link PiniaColadaDelay} plugin.
35
35
  */
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.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, 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, TDataInitial> extends PiniaColadaDelayOptions {}\n\n interface UseQueryOptionsGlobal 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":";AASA,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":[]}
1
+ {"version":3,"sources":["../src/index.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, 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<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> {\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":";AASA,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.6",
7
+ "version": "0.1.0",
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.15.0"
62
+ "@pinia/colada": ">=0.16.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@pinia/colada": "^0.15.0"
65
+ "@pinia/colada": "^0.16.0"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",