@spoosh/plugin-debounce 0.2.0 → 0.2.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Request debouncing plugin for Spoosh - waits for inactivity before fetching.
4
4
 
5
- **[Documentation](https://spoosh.dev/docs/plugins/debounce)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
5
+ **[Documentation](https://spoosh.dev/docs/react/plugins/debounce)** · **Requirements:** TypeScript >= 5.0 · **Peer Dependencies:** `@spoosh/core`
6
6
 
7
7
  ## Installation
8
8
 
package/dist/index.d.mts CHANGED
@@ -33,7 +33,7 @@ declare module "@spoosh/core" {
33
33
  * Delays requests until input stops changing, useful for search inputs
34
34
  * to avoid excessive API calls while typing.
35
35
  *
36
- * @see {@link https://spoosh.dev/docs/plugins/debounce | Debounce Plugin Documentation}
36
+ * @see {@link https://spoosh.dev/docs/react/plugins/debounce | Debounce Plugin Documentation}
37
37
  *
38
38
  * @example
39
39
  * ```ts
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ declare module "@spoosh/core" {
33
33
  * Delays requests until input stops changing, useful for search inputs
34
34
  * to avoid excessive API calls while typing.
35
35
  *
36
- * @see {@link https://spoosh.dev/docs/plugins/debounce | Debounce Plugin Documentation}
36
+ * @see {@link https://spoosh.dev/docs/react/plugins/debounce | Debounce Plugin Documentation}
37
37
  *
38
38
  * @example
39
39
  * ```ts
package/dist/index.js CHANGED
@@ -37,6 +37,19 @@ function debouncePlugin() {
37
37
  return {
38
38
  name: "spoosh:debounce",
39
39
  operations: ["read", "infiniteRead"],
40
+ lifecycle: {
41
+ onUnmount: (context) => {
42
+ const { path, method } = context;
43
+ const stableKey = `${path.join("/")}:${method}`;
44
+ const existingTimer = timers.get(stableKey);
45
+ if (existingTimer) {
46
+ clearTimeout(existingTimer);
47
+ timers.delete(stableKey);
48
+ }
49
+ latestQueryKeys.delete(stableKey);
50
+ prevRequests.delete(stableKey);
51
+ }
52
+ },
40
53
  middleware: async (context, next) => {
41
54
  const pluginOptions = context.pluginOptions;
42
55
  const debounceOption = pluginOptions?.debounce;
package/dist/index.mjs CHANGED
@@ -11,6 +11,19 @@ function debouncePlugin() {
11
11
  return {
12
12
  name: "spoosh:debounce",
13
13
  operations: ["read", "infiniteRead"],
14
+ lifecycle: {
15
+ onUnmount: (context) => {
16
+ const { path, method } = context;
17
+ const stableKey = `${path.join("/")}:${method}`;
18
+ const existingTimer = timers.get(stableKey);
19
+ if (existingTimer) {
20
+ clearTimeout(existingTimer);
21
+ timers.delete(stableKey);
22
+ }
23
+ latestQueryKeys.delete(stableKey);
24
+ prevRequests.delete(stableKey);
25
+ }
26
+ },
14
27
  middleware: async (context, next) => {
15
28
  const pluginOptions = context.pluginOptions;
16
29
  const debounceOption = pluginOptions?.debounce;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-debounce",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Request debouncing plugin for Spoosh - waits for inactivity before fetching",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/nxnom/spoosh.git",
8
+ "url": "git+https://github.com/spooshdev/spoosh.git",
9
9
  "directory": "packages/plugin-debounce"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/nxnom/spoosh/issues"
12
+ "url": "https://github.com/spooshdev/spoosh/issues"
13
13
  },
14
- "homepage": "https://spoosh.dev/react/docs/plugins/debounce",
14
+ "homepage": "https://spoosh.dev/docs/react/plugins/debounce",
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
@@ -36,7 +36,7 @@
36
36
  "@spoosh/core": ">=0.6.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.6.0",
39
+ "@spoosh/core": "0.10.0",
40
40
  "@spoosh/test-utils": "0.1.5"
41
41
  },
42
42
  "scripts": {