@pushwoosh/kit-helpers 4.12.4 → 4.12.6

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/callWithRetry.js CHANGED
@@ -27,7 +27,6 @@ export const callWithRetry = async (operation, policy) => {
27
27
  };
28
28
  for (let attempt = 1; attempt <= policy.attempts; attempt += 1) {
29
29
  try {
30
- // eslint-disable-next-line no-await-in-loop
31
30
  const result = await operation(attempt);
32
31
  if (!policy.until || policy.until(result)) {
33
32
  return result;
@@ -45,7 +44,6 @@ export const callWithRetry = async (operation, policy) => {
45
44
  };
46
45
  }
47
46
  if (attempt < policy.attempts) {
48
- // eslint-disable-next-line no-await-in-loop
49
47
  await sleep(policy.delay);
50
48
  }
51
49
  }
package/expand.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createElement as _createElement } from "react";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- /* eslint-disable react/require-default-props, react/jsx-no-bind */
4
3
  import { useEffect, useRef, useState } from 'react';
5
4
  import { CSSTransition, TransitionGroup } from 'react-transition-group';
6
5
  import styled, { css } from 'styled-components';
@@ -14,7 +14,6 @@ export default function useAsyncFn(fn, deps = [], initialState = getDefaultState
14
14
  const callback = useCallback(({
15
15
  reset
16
16
  } = {}) => {
17
- // eslint-disable-next-line no-plusplus
18
17
  const callId = ++lastCallId.current;
19
18
  const canSet = () => isMounted() && callId === lastCallId.current;
20
19
  if (canSet()) {
@@ -14,7 +14,6 @@ export default function useAsyncFunction(fn) {
14
14
  const isMounted = useMountedState();
15
15
  const [state, setState] = useState(getDefaultState);
16
16
  const execute = usePersistentFunction((...args) => {
17
- // eslint-disable-next-line no-plusplus
18
17
  const count = ++countRef.current;
19
18
  const canSet = () => isMounted() && count === countRef.current;
20
19
  if (canSet()) {
@@ -48,7 +48,6 @@ export function useClickAway(use, ref,
48
48
  cb) {
49
49
  // Persist the callback function to avoid re-subscribing on every render
50
50
  const persistentCb = usePersistentFunction(cb);
51
- // eslint-disable-next-line consistent-return
52
51
  useEffect(() => {
53
52
  // Only subscribe if the hook is active and the ref points to an element
54
53
  if (use && ref.current) {
@@ -44,4 +44,4 @@
44
44
  * return <div>...</div>;
45
45
  * };
46
46
  */
47
- export default function usePersistentFunction<Args extends any[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return;
47
+ export default function usePersistentFunction<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return;
@@ -1,4 +1,4 @@
1
- import { useCallback, useRef } from 'react';
1
+ import { useInsertionEffect, useRef } from 'react';
2
2
  /**
3
3
  * Creates a stable function reference that always calls the latest version of a callback.
4
4
  *
@@ -46,10 +46,17 @@ import { useCallback, useRef } from 'react';
46
46
  * };
47
47
  */
48
48
  export default function usePersistentFunction(callback) {
49
- // Store the latest callback in a ref
50
- const callbackRef = useRef(callback);
51
- // Update the ref to the latest callback on each render
52
- callbackRef.current = callback;
53
- // Create a stable function reference that calls the latest callback
54
- return useCallback((...args) => callbackRef.current(...args), []);
49
+ const holderRef = useRef(null);
50
+ if (holderRef.current === null) {
51
+ const created = {
52
+ latest: callback,
53
+ fn: (...args) => created.latest(...args)
54
+ };
55
+ holderRef.current = created;
56
+ }
57
+ const holder = holderRef.current;
58
+ useInsertionEffect(() => {
59
+ holder.latest = callback;
60
+ });
61
+ return holder.fn;
55
62
  }
package/package.json CHANGED
@@ -1,37 +1,25 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-helpers",
3
- "version": "4.12.4",
3
+ "version": "4.12.6",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "sideEffects": false,
9
9
  "publishConfig": {
10
- "access": "public"
10
+ "access": "public",
11
+ "directory": "dist"
11
12
  },
12
- "scripts": {
13
- "start": "npm run playground",
14
- "build": "pushwoosh-engine lib:build",
15
- "playground": "pushwoosh-engine lib:playground",
16
- "check": "npm run check:lint && npm run check:types",
17
- "check:lint": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src",
18
- "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src --fix",
19
- "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types"
20
- },
21
- "pre-commit": "check",
22
13
  "dependencies": {
23
14
  "react-transition-group": "^4.4.5"
24
15
  },
25
16
  "devDependencies": {
26
- "@pushwoosh/frontend-builder-engine": "^3.1.0",
27
- "@pushwoosh/kit-constants": "^1.6.0",
28
- "@types/react": "^18.3.2",
29
- "@types/react-dom": "^18.3.0",
17
+ "@pushwoosh/kit-constants": "^2.1.0",
18
+ "@types/react": "^18.3.31",
19
+ "@types/react-dom": "^18.3.7",
30
20
  "@types/react-transition-group": "^4.4.10",
31
21
  "@types/styled-components": "^5.1.34",
32
22
  "@types/webpack-env": "^1.18.8",
33
- "cross-env": "^7.0.3",
34
- "pre-commit": "^1.2.2",
35
23
  "react": "^18.3.1",
36
24
  "react-dom": "^18.3.1",
37
25
  "styled-components": "^5.3.11"
@@ -41,6 +29,15 @@
41
29
  "styled-components": ">=5.3.3"
42
30
  },
43
31
  "engines": {
44
- "node": ">= 18"
32
+ "node": ">= 24"
33
+ },
34
+ "scripts": {
35
+ "start": "pnpm run playground",
36
+ "build": "pushwoosh-engine lib:build",
37
+ "playground": "pushwoosh-engine lib:playground",
38
+ "check": "pnpm run check:lint && pnpm run check:types",
39
+ "check:lint": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src",
40
+ "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src --fix",
41
+ "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types"
45
42
  }
46
- }
43
+ }