@dr.pogodin/react-utils 1.29.2 → 1.30.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.
@@ -4,7 +4,7 @@ import * as isomorphy from './isomorphy';
4
4
  import time from './time';
5
5
  import * as webpack from './webpack';
6
6
  import type * as JuT from './jest';
7
- export { Barrier, Emitter, Semaphore } from '@dr.pogodin/js-utils';
7
+ export { Barrier, Emitter, Semaphore, withRetries, } from '@dr.pogodin/js-utils';
8
8
  export { getSsrContext } from './globalState';
9
9
  export { default as splitComponent } from './splitComponent';
10
10
  type ThemedT = typeof themedImpl & {
@@ -13,40 +13,4 @@ type ThemedT = typeof themedImpl & {
13
13
  };
14
14
  declare const themed: ThemedT;
15
15
  declare const JU: typeof JuT | null;
16
- /**
17
- * @category Utilities
18
- * @global
19
- * @func withRetries
20
- * @desc
21
- * ```js
22
- * import { withRetries } from '@dr.pogodin/react-utils';
23
- * ```
24
- * Attempts to perform given asynchronous `action` up to `maxRetries` times,
25
- * with the given `interval` between attempts. If any attempt is successful,
26
- * the result is returned immediately, with no further attempts done;
27
- * otherwise, if all attempts fail, the result Promise rejects after the last
28
- * attempt.
29
- * @param {function} action
30
- * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults
31
- * to 5 attempts.
32
- * @param {number} [interval=1000] Optional. Interval between retries [ms].
33
- * Defaults to 1 second.
34
- * @return {Promise} Resolves to the result of successful operation, or
35
- * rejects with the error from the latst failed attempt.
36
- * @example
37
- * import { withRetries } from '@dr.pogodin/react-utils';
38
- *
39
- * let firstCall = true;
40
- *
41
- * function sampleAction() {
42
- * if (!firstCall) return 'success';
43
- * firstCall = false;
44
- * throw Error('The first call to this method fails');
45
- * }
46
- *
47
- * withRetries(sampleAction).then(console.log);
48
- * // It will print 'success' after one second, once the second attempt
49
- * // is performed.
50
- */
51
- export declare function withRetries(action: () => Promise<unknown>, maxRetries?: number, interval?: number): Promise<unknown>;
52
16
  export { type Theme, config, isomorphy, JU, themed, ThemeProvider, time, webpack, };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.29.2",
2
+ "version": "1.30.0",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -11,12 +11,12 @@
11
11
  "@babel/runtime": "^7.23.9",
12
12
  "@dr.pogodin/babel-plugin-react-css-modules": "^6.12.0",
13
13
  "@dr.pogodin/csurf": "^1.13.0",
14
- "@dr.pogodin/js-utils": "^0.0.7",
14
+ "@dr.pogodin/js-utils": "^0.0.8",
15
15
  "@dr.pogodin/react-global-state": "^0.12.0",
16
16
  "@dr.pogodin/react-themes": "^1.6.0",
17
17
  "@jest/environment": "^29.7.0",
18
18
  "axios": "^1.6.7",
19
- "commander": "^11.1.0",
19
+ "commander": "^12.0.0",
20
20
  "compression": "^1.7.4",
21
21
  "config": "^3.3.11",
22
22
  "cookie": "^0.6.0",
@@ -73,8 +73,8 @@
73
73
  "@types/morgan": "^1.9.9",
74
74
  "@types/node-forge": "^1.3.11",
75
75
  "@types/pretty": "^2.0.3",
76
- "@types/react": "^18.2.51",
77
- "@types/react-dom": "^18.2.18",
76
+ "@types/react": "^18.2.55",
77
+ "@types/react-dom": "^18.2.19",
78
78
  "@types/react-helmet": "^6.1.11",
79
79
  "@types/react-test-renderer": "^18.0.7",
80
80
  "@types/request-ip": "^0.0.41",
@@ -83,8 +83,8 @@
83
83
  "@types/supertest": "^6.0.2",
84
84
  "@types/uuid": "^9.0.8",
85
85
  "@types/webpack": "^5.28.5",
86
- "@typescript-eslint/eslint-plugin": "^6.20.0",
87
- "@typescript-eslint/parser": "^6.20.0",
86
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
87
+ "@typescript-eslint/parser": "^6.21.0",
88
88
  "autoprefixer": "^10.4.17",
89
89
  "babel-jest": "^29.7.0",
90
90
  "babel-loader": "^9.1.3",
@@ -108,7 +108,7 @@
108
108
  "mini-css-extract-plugin": "^2.8.0",
109
109
  "mockdate": "^3.0.5",
110
110
  "nodelist-foreach-polyfill": "^1.2.0",
111
- "postcss": "^8.4.33",
111
+ "postcss": "^8.4.35",
112
112
  "postcss-loader": "^8.1.0",
113
113
  "postcss-scss": "^4.0.9",
114
114
  "pretty": "^2.0.0",
@@ -12,7 +12,12 @@ import * as webpack from './webpack';
12
12
 
13
13
  import type * as JuT from './jest';
14
14
 
15
- export { Barrier, Emitter, Semaphore } from '@dr.pogodin/js-utils';
15
+ export {
16
+ Barrier,
17
+ Emitter,
18
+ Semaphore,
19
+ withRetries,
20
+ } from '@dr.pogodin/js-utils';
16
21
 
17
22
  export { getSsrContext } from './globalState';
18
23
  export { default as splitComponent } from './splitComponent';
@@ -41,58 +46,6 @@ const JU: typeof JuT | null = env !== 'production'
41
46
  ? webpack.requireWeak('./jest', __dirname) as typeof JuT | null
42
47
  : null;
43
48
 
44
- /**
45
- * @category Utilities
46
- * @global
47
- * @func withRetries
48
- * @desc
49
- * ```js
50
- * import { withRetries } from '@dr.pogodin/react-utils';
51
- * ```
52
- * Attempts to perform given asynchronous `action` up to `maxRetries` times,
53
- * with the given `interval` between attempts. If any attempt is successful,
54
- * the result is returned immediately, with no further attempts done;
55
- * otherwise, if all attempts fail, the result Promise rejects after the last
56
- * attempt.
57
- * @param {function} action
58
- * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults
59
- * to 5 attempts.
60
- * @param {number} [interval=1000] Optional. Interval between retries [ms].
61
- * Defaults to 1 second.
62
- * @return {Promise} Resolves to the result of successful operation, or
63
- * rejects with the error from the latst failed attempt.
64
- * @example
65
- * import { withRetries } from '@dr.pogodin/react-utils';
66
- *
67
- * let firstCall = true;
68
- *
69
- * function sampleAction() {
70
- * if (!firstCall) return 'success';
71
- * firstCall = false;
72
- * throw Error('The first call to this method fails');
73
- * }
74
- *
75
- * withRetries(sampleAction).then(console.log);
76
- * // It will print 'success' after one second, once the second attempt
77
- * // is performed.
78
- */
79
- export async function withRetries(
80
- action: () => Promise<unknown>,
81
- maxRetries = 5,
82
- interval = 1000,
83
- ) {
84
- /* eslint-disable no-await-in-loop */
85
- for (let n = 1; ; ++n) {
86
- try {
87
- return await action();
88
- } catch (error) {
89
- if (n < maxRetries) await time.timer(interval);
90
- else throw error;
91
- }
92
- }
93
- /* eslint-enable no-await-in-loop */
94
- }
95
-
96
49
  export {
97
50
  type Theme,
98
51
  config,