@sima-land/isomorph 11.0.0-alpha.0 → 11.0.0-alpha.1
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/{dist/cache → cache}/types.d.ts +0 -0
- package/{dist/utils/webpack/module-federation → cache}/types.js +0 -0
- package/{dist/cache → cache}/types.js.map +0 -0
- package/{dist/config → config}/browser.d.ts +0 -0
- package/{dist/config → config}/browser.js +0 -0
- package/{dist/config → config}/browser.js.map +0 -0
- package/{dist/config → config}/index.d.ts +0 -0
- package/{dist/config → config}/index.js +0 -0
- package/{dist/config → config}/index.js.map +0 -0
- package/{dist/config → config}/node.d.ts +0 -0
- package/{dist/config → config}/node.js +0 -0
- package/{dist/config → config}/node.js.map +0 -0
- package/{dist/config → config}/types.d.ts +0 -0
- package/{dist/tracer → config}/types.js +0 -0
- package/{dist/config → config}/types.js.map +0 -0
- package/{dist/config → config}/utils.d.ts +0 -0
- package/{dist/config → config}/utils.js +0 -0
- package/{dist/config → config}/utils.js.map +0 -0
- package/{dist/container → container}/application.d.ts +0 -0
- package/{dist/container → container}/application.js +0 -0
- package/{dist/container → container}/application.js.map +0 -0
- package/{dist/container → container}/index.d.ts +0 -0
- package/{dist/container → container}/index.js +0 -0
- package/{dist/container → container}/index.js.map +0 -0
- package/{dist/container → container}/types.d.ts +0 -0
- package/{dist/saga-runner → container}/types.js +0 -0
- package/{dist/container → container}/types.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/browser.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/browser.js +0 -0
- package/{dist/error-tracker → error-tracker}/browser.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/node.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/node.js +0 -0
- package/{dist/error-tracker → error-tracker}/node.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/types.d.ts +0 -0
- package/{dist/preset → error-tracker}/types.js +0 -0
- package/{dist/error-tracker → error-tracker}/types.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/utils.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/utils.js +0 -0
- package/{dist/error-tracker → error-tracker}/utils.js.map +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js.map +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js.map +0 -0
- package/{dist/http-client → http-client}/types.d.ts +0 -0
- package/{dist/logger → http-client}/types.js +0 -0
- package/{dist/http-client → http-client}/types.js.map +0 -0
- package/{dist/http-client → http-client}/utils.d.ts +0 -0
- package/{dist/http-client → http-client}/utils.js +0 -0
- package/{dist/http-client → http-client}/utils.js.map +0 -0
- package/{dist/http-server → http-server}/constants.d.ts +0 -0
- package/{dist/http-server → http-server}/constants.js +0 -0
- package/{dist/http-server → http-server}/constants.js.map +0 -0
- package/{dist/http-server → http-server}/handler/health-check.d.ts +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/logging.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/tracing.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/tracing.js +0 -0
- package/{dist/http-server → http-server}/middleware/tracing.js.map +0 -0
- package/http-server/template/index.d.ts +1 -0
- package/http-server/template/index.js +36 -0
- package/http-server/template/index.js.map +1 -0
- package/{dist/http-server → http-server}/types.d.ts +8 -0
- package/{dist/http-server → http-server}/types.js +0 -0
- package/{dist/http-server → http-server}/types.js.map +0 -0
- package/{dist/http-server → http-server}/utils.d.ts +5 -1
- package/{dist/http-server → http-server}/utils.js +16 -4
- package/http-server/utils.js.map +1 -0
- package/{dist/logger → logger}/handler/console.d.ts +0 -0
- package/{dist/logger → logger}/handler/console.js +0 -0
- package/{dist/logger → logger}/handler/console.js.map +0 -0
- package/{dist/logger → logger}/handler/sentry.d.ts +0 -0
- package/{dist/logger → logger}/handler/sentry.js +0 -0
- package/{dist/logger → logger}/handler/sentry.js.map +0 -0
- package/{dist/logger → logger}/index.d.ts +0 -0
- package/{dist/logger → logger}/index.js +0 -0
- package/{dist/logger → logger}/index.js.map +0 -0
- package/{dist/logger → logger}/types.d.ts +0 -0
- package/{dist/http-client → logger}/types.js +0 -0
- package/{dist/logger → logger}/types.js.map +0 -0
- package/{dist/metrics → metrics}/constants.d.ts +0 -0
- package/{dist/metrics → metrics}/constants.js +0 -0
- package/{dist/metrics → metrics}/constants.js.map +0 -0
- package/{dist/metrics → metrics}/node.d.ts +0 -0
- package/{dist/metrics → metrics}/node.js +0 -0
- package/{dist/metrics → metrics}/node.js.map +0 -0
- package/package.json +5 -10
- package/{dist/preset → preset}/index.d.ts +0 -0
- package/{dist/preset → preset}/index.js +5 -3
- package/preset/index.js.map +1 -0
- package/{dist/preset → preset}/node/index.d.ts +0 -0
- package/{dist/preset → preset}/node/index.js +0 -0
- package/{dist/preset → preset}/node/index.js.map +0 -0
- package/{dist/preset → preset}/node/response.d.ts +6 -1
- package/{dist/preset → preset}/node/response.js +28 -2
- package/preset/node/response.js.map +1 -0
- package/{dist/preset → preset}/types.d.ts +2 -2
- package/{dist/error-tracker → preset}/types.js +0 -0
- package/{dist/preset → preset}/types.js.map +0 -0
- package/{dist/saga-runner → saga-runner}/index.d.ts +0 -0
- package/{dist/saga-runner → saga-runner}/index.js +3 -1
- package/saga-runner/index.js.map +1 -0
- package/{dist/saga-runner → saga-runner}/types.d.ts +0 -0
- package/{dist/container → saga-runner}/types.js +0 -0
- package/{dist/saga-runner → saga-runner}/types.js.map +0 -0
- package/{dist/tokens.d.ts → tokens.d.ts} +2 -1
- package/{dist/tokens.js → tokens.js} +1 -0
- package/{dist/tokens.js.map → tokens.js.map} +1 -1
- package/{dist/tracer → tracer}/node.d.ts +0 -0
- package/{dist/tracer → tracer}/node.js +0 -0
- package/{dist/tracer → tracer}/node.js.map +0 -0
- package/{dist/tracer → tracer}/types.d.ts +0 -0
- package/{dist/config → tracer}/types.js +0 -0
- package/{dist/tracer → tracer}/types.js.map +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js.map +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js.map +0 -0
- package/{dist/utils → utils}/browser/storage/index.d.ts +0 -0
- package/{dist/utils → utils}/browser/storage/index.js +0 -0
- package/{dist/utils → utils}/browser/storage/index.js.map +0 -0
- package/{dist/utils → utils}/number.d.ts +0 -0
- package/{dist/utils → utils}/number.js +0 -0
- package/{dist/utils → utils}/number.js.map +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.d.ts +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.js +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.js.map +0 -0
- package/{dist/utils → utils}/redux/remote-data.d.ts +0 -0
- package/{dist/utils → utils}/redux/remote-data.js +0 -0
- package/{dist/utils → utils}/redux/remote-data.js.map +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.d.ts +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.d.ts +0 -0
- package/{dist/cache → utils/webpack/module-federation}/types.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js.map +0 -0
- package/LICENSE +0 -201
- package/dist/http-server/utils.js.map +0 -1
- package/dist/preset/index.js.map +0 -1
- package/dist/preset/node/response.js.map +0 -1
- package/dist/saga-runner/index.js.map +0 -1
- package/readme.md +0 -23
- package/src/cache/types.ts +0 -7
- package/src/config/browser.ts +0 -10
- package/src/config/index.ts +0 -18
- package/src/config/node.ts +0 -18
- package/src/config/types.ts +0 -9
- package/src/config/utils.ts +0 -7
- package/src/container/application.ts +0 -91
- package/src/container/index.ts +0 -79
- package/src/container/types.ts +0 -17
- package/src/error-tracker/browser.ts +0 -14
- package/src/error-tracker/node.ts +0 -14
- package/src/error-tracker/types.ts +0 -22
- package/src/error-tracker/utils.ts +0 -18
- package/src/http-client/middleware/cookie.ts +0 -73
- package/src/http-client/middleware/tracing.ts +0 -79
- package/src/http-client/types.ts +0 -8
- package/src/http-client/utils.ts +0 -76
- package/src/http-server/constants.ts +0 -4
- package/src/http-server/handler/health-check.ts +0 -13
- package/src/http-server/middleware/logging.ts +0 -34
- package/src/http-server/middleware/metrics.ts +0 -87
- package/src/http-server/middleware/tracing.ts +0 -35
- package/src/http-server/types.ts +0 -29
- package/src/http-server/utils.ts +0 -105
- package/src/logger/handler/console.ts +0 -35
- package/src/logger/handler/sentry.ts +0 -38
- package/src/logger/index.ts +0 -31
- package/src/logger/types.ts +0 -28
- package/src/metrics/constants.ts +0 -4
- package/src/metrics/node.ts +0 -54
- package/src/preset/index.ts +0 -24
- package/src/preset/node/index.ts +0 -101
- package/src/preset/node/response.ts +0 -57
- package/src/preset/types.ts +0 -9
- package/src/saga-runner/index.ts +0 -59
- package/src/saga-runner/types.ts +0 -13
- package/src/tokens.ts +0 -54
- package/src/tracer/node.ts +0 -40
- package/src/tracer/types.ts +0 -3
- package/src/utils/browser/analytics/__test__/data-layer.test.ts +0 -50
- package/src/utils/browser/analytics/__test__/oko.test.tsx +0 -143
- package/src/utils/browser/analytics/data-layer.ts +0 -12
- package/src/utils/browser/analytics/oko.ts +0 -44
- package/src/utils/browser/storage/index.ts +0 -75
- package/src/utils/number.ts +0 -8
- package/src/utils/react/error-handlers/__test__/__snapshots__/index.test.tsx.snap +0 -27
- package/src/utils/react/error-handlers/__test__/index.test.tsx +0 -64
- package/src/utils/react/error-handlers/index.tsx +0 -62
- package/src/utils/redux/__test__/remote-data.test.ts +0 -50
- package/src/utils/redux/remote-data.ts +0 -34
- package/src/utils/redux-saga/__test__/take-chain.test.ts +0 -141
- package/src/utils/redux-saga/take-chain.ts +0 -65
- package/src/utils/webpack/module-federation/__test__/index.test.ts +0 -246
- package/src/utils/webpack/module-federation/index.ts +0 -92
- package/src/utils/webpack/module-federation/types.ts +0 -44
- package/src/utils/webpack/module-federation/utils.ts +0 -43
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { isFunction } from 'lodash';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Отправка аналитики в око.
|
|
5
|
-
* @param eventData Данные события для отправки.
|
|
6
|
-
*/
|
|
7
|
-
export const dataLayerPush = (eventData: Record<string, any>) => {
|
|
8
|
-
const win: any = window;
|
|
9
|
-
|
|
10
|
-
// копируем объект так как window.dataLayer.push может менять аргумент в процессе работы
|
|
11
|
-
isFunction(win.dataLayer?.push) && win.dataLayer.push({ ...eventData });
|
|
12
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { isEqual, isFunction } from 'lodash';
|
|
3
|
-
|
|
4
|
-
export type OkoEvent = Record<string, any>;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Отправка аналитики в око.
|
|
8
|
-
* @param eventData Данные события для отправки.
|
|
9
|
-
*/
|
|
10
|
-
export const okoPush = (eventData: OkoEvent) => {
|
|
11
|
-
const win: any = window;
|
|
12
|
-
|
|
13
|
-
// копируем объект так как window.oko.push меняет свой аргумент в процессе выполнения
|
|
14
|
-
isFunction(win.oko?.push) && win.oko.push({ ...eventData });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Хук, возвращающий функцию, которая отправит аналитику в ОКО.
|
|
19
|
-
* @param data Данные события для отправки в ОКО.
|
|
20
|
-
* @return Функция.
|
|
21
|
-
*/
|
|
22
|
-
export const useOkoPush = (data: OkoEvent) => {
|
|
23
|
-
const dataRef = useRef<OkoEvent>();
|
|
24
|
-
const fnRef = useRef<() => void>();
|
|
25
|
-
|
|
26
|
-
if (!dataRef.current) {
|
|
27
|
-
dataRef.current = { ...data };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!fnRef.current) {
|
|
31
|
-
fnRef.current = () => okoPush(dataRef.current as OkoEvent);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!isEqual(data, dataRef.current)) {
|
|
35
|
-
throw Error(
|
|
36
|
-
[
|
|
37
|
-
'useAnalytics: Данные для аналитики изменились.',
|
|
38
|
-
'Если необходимо использовать динамические данные, вынесите логику из React-компонента.',
|
|
39
|
-
].join('\n'),
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return fnRef.current;
|
|
44
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc, jsdoc/require-jsdoc */
|
|
2
|
-
|
|
3
|
-
export interface StorageUtils
|
|
4
|
-
extends Pick<Storage, 'clear' | 'getItem' | 'key' | 'removeItem' | 'setItem' | 'length'> {
|
|
5
|
-
isAvailable: () => boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createStorageUtils(getStorage: () => Storage): StorageUtils {
|
|
9
|
-
function isAvailable(): boolean {
|
|
10
|
-
try {
|
|
11
|
-
const testKey = `local_storage_test_key::${Date.now()}`;
|
|
12
|
-
|
|
13
|
-
getStorage().setItem(testKey, testKey);
|
|
14
|
-
getStorage().removeItem(testKey);
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
} catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function clear(): void {
|
|
23
|
-
if (isAvailable()) {
|
|
24
|
-
getStorage().clear();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getItem(name: string): string | null {
|
|
29
|
-
if (isAvailable()) {
|
|
30
|
-
return getStorage().getItem(name);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function key(index: number): string | null {
|
|
37
|
-
if (isAvailable()) {
|
|
38
|
-
return getStorage().key(index);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function removeItem(name: string): void {
|
|
44
|
-
if (isAvailable()) {
|
|
45
|
-
getStorage().removeItem(name);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function setItem(name: string, value: string): void {
|
|
50
|
-
if (isAvailable()) {
|
|
51
|
-
getStorage().setItem(name, value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function length(): number {
|
|
56
|
-
if (isAvailable()) {
|
|
57
|
-
return getStorage().length;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
isAvailable,
|
|
65
|
-
|
|
66
|
-
clear,
|
|
67
|
-
getItem,
|
|
68
|
-
key,
|
|
69
|
-
removeItem,
|
|
70
|
-
setItem,
|
|
71
|
-
get length() {
|
|
72
|
-
return length();
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
package/src/utils/number.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`ErrorBoundary should call captureException 1`] = `<div />`;
|
|
4
|
-
|
|
5
|
-
exports[`ErrorBoundary should render children component 1`] = `
|
|
6
|
-
<div>
|
|
7
|
-
<div>
|
|
8
|
-
Normal component
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
exports[`ErrorBoundary should render fallback component 1`] = `
|
|
14
|
-
<div>
|
|
15
|
-
<div>
|
|
16
|
-
Fallback
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
exports[`SafeSuspense should render with props 1`] = `
|
|
22
|
-
<div>
|
|
23
|
-
<div>
|
|
24
|
-
Normal component
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
`;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { ErrorBoundary, SafeSuspense } from '..';
|
|
4
|
-
|
|
5
|
-
describe('ErrorBoundary', () => {
|
|
6
|
-
const error = new Error('Test error');
|
|
7
|
-
|
|
8
|
-
const FailedComponent = () => {
|
|
9
|
-
throw error;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
it('should render children component', () => {
|
|
13
|
-
const { container } = render(
|
|
14
|
-
<ErrorBoundary fallback={null}>
|
|
15
|
-
<div>Normal component</div>
|
|
16
|
-
</ErrorBoundary>,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
expect(container.textContent).toContain('Normal component');
|
|
20
|
-
expect(container).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should render fallback component', () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
<ErrorBoundary fallback={<div>Fallback</div>}>
|
|
26
|
-
<>
|
|
27
|
-
<div>Normal component</div>
|
|
28
|
-
<FailedComponent />
|
|
29
|
-
</>
|
|
30
|
-
</ErrorBoundary>,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(container.textContent).toContain('Fallback');
|
|
34
|
-
expect(container).toMatchSnapshot();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should call captureException', () => {
|
|
38
|
-
const handlerException = jest.fn();
|
|
39
|
-
|
|
40
|
-
const { container } = render(
|
|
41
|
-
<ErrorBoundary fallback={null} onError={handlerException}>
|
|
42
|
-
<>
|
|
43
|
-
<div>Normal component</div>
|
|
44
|
-
<FailedComponent />
|
|
45
|
-
</>
|
|
46
|
-
</ErrorBoundary>,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(handlerException).toBeCalledWith(error, { componentStack: expect.any(String) });
|
|
50
|
-
expect(container).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('SafeSuspense', () => {
|
|
55
|
-
it('should render with props', () => {
|
|
56
|
-
const { container } = render(
|
|
57
|
-
<SafeSuspense fallback={<div>Fallback</div>} onError={jest.fn()}>
|
|
58
|
-
<div>Normal component</div>
|
|
59
|
-
</SafeSuspense>,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
expect(container).toMatchSnapshot();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface Props {
|
|
4
|
-
/** Дочерний компонент. */
|
|
5
|
-
children: NonNullable<React.ReactNode> | null;
|
|
6
|
-
|
|
7
|
-
/** Запасной элемент, если возникла ошибка. */
|
|
8
|
-
fallback: NonNullable<React.ReactNode> | null;
|
|
9
|
-
|
|
10
|
-
/** Функция для логирования ошибки. */
|
|
11
|
-
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Обработчик ошибок в React-компонентах.
|
|
16
|
-
*/
|
|
17
|
-
export class ErrorBoundary extends React.Component<Props, { hasError: boolean }> {
|
|
18
|
-
/**
|
|
19
|
-
* @param props Свойства.
|
|
20
|
-
*/
|
|
21
|
-
constructor(props: Props) {
|
|
22
|
-
super(props);
|
|
23
|
-
|
|
24
|
-
this.state = { hasError: false };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @inheritdoc */
|
|
28
|
-
static getDerivedStateFromError() {
|
|
29
|
-
return { hasError: true };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @inheritdoc */
|
|
33
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
34
|
-
const { onError } = this.props;
|
|
35
|
-
|
|
36
|
-
onError?.(error, errorInfo);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Рендер.
|
|
41
|
-
* @return Дочерний элемент либо запасное значение.
|
|
42
|
-
*/
|
|
43
|
-
render() {
|
|
44
|
-
const { children, fallback } = this.props;
|
|
45
|
-
|
|
46
|
-
return this.state.hasError ? fallback : children;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Обертка над Suspense c перехватом ошибок.
|
|
52
|
-
* @todo Возможно этот компонент не нужен...
|
|
53
|
-
* @param props Свойства.
|
|
54
|
-
* @return Элемент.
|
|
55
|
-
*/
|
|
56
|
-
export const SafeSuspense = ({ children, fallback, onError }: Props) => (
|
|
57
|
-
<React.Suspense fallback={fallback}>
|
|
58
|
-
<ErrorBoundary fallback={fallback} onError={onError}>
|
|
59
|
-
{children}
|
|
60
|
-
</ErrorBoundary>
|
|
61
|
-
</React.Suspense>
|
|
62
|
-
);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
-
import { createRemoteDataReducers, RemoteDataState, STATUS } from '../remote-data';
|
|
3
|
-
|
|
4
|
-
interface TestState extends RemoteDataState<number, string> {
|
|
5
|
-
foo: 'bar';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('createGenericSlice', () => {
|
|
9
|
-
const initialState: TestState = {
|
|
10
|
-
data: 0,
|
|
11
|
-
error: '',
|
|
12
|
-
status: STATUS.initial,
|
|
13
|
-
foo: 'bar',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const { reducer, actions } = createSlice({
|
|
17
|
-
name: 'user',
|
|
18
|
-
initialState,
|
|
19
|
-
reducers: createRemoteDataReducers<TestState>(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should handle request action', () => {
|
|
23
|
-
const actual = reducer(initialState, actions.request());
|
|
24
|
-
|
|
25
|
-
expect(actual).toEqual({
|
|
26
|
-
...initialState,
|
|
27
|
-
status: STATUS.fetching,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should handle success action', () => {
|
|
32
|
-
const actual = reducer(initialState, actions.success(234));
|
|
33
|
-
|
|
34
|
-
expect(actual).toEqual({
|
|
35
|
-
...initialState,
|
|
36
|
-
data: 234,
|
|
37
|
-
status: STATUS.success,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should handle failure action', () => {
|
|
42
|
-
const actual = reducer(initialState, actions.failure('error message here'));
|
|
43
|
-
|
|
44
|
-
expect(actual).toEqual({
|
|
45
|
-
...initialState,
|
|
46
|
-
error: 'error message here',
|
|
47
|
-
status: STATUS.failure,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { PayloadAction, Draft } from '@reduxjs/toolkit';
|
|
2
|
-
|
|
3
|
-
export type Status = 'initial' | 'fetching' | 'success' | 'failure';
|
|
4
|
-
|
|
5
|
-
export interface RemoteDataState<TData, TError> {
|
|
6
|
-
data: TData;
|
|
7
|
-
error: TError;
|
|
8
|
-
status: Status;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const STATUS: Record<Status, Status> = {
|
|
12
|
-
initial: 'initial',
|
|
13
|
-
fetching: 'fetching',
|
|
14
|
-
success: 'success',
|
|
15
|
-
failure: 'failure',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Возвращает набор обработчиков для работы с удаленными данными.
|
|
20
|
-
* @return Набор.
|
|
21
|
-
*/
|
|
22
|
-
export const createRemoteDataReducers = <S extends RemoteDataState<any, any>>() => ({
|
|
23
|
-
request: (state: Draft<S>) => {
|
|
24
|
-
state.status = STATUS.fetching;
|
|
25
|
-
},
|
|
26
|
-
success: (state: Draft<S>, action: PayloadAction<S['data']>) => {
|
|
27
|
-
state.data = action.payload;
|
|
28
|
-
state.status = STATUS.success;
|
|
29
|
-
},
|
|
30
|
-
failure: (state: Draft<S>, action: PayloadAction<S['error']>) => {
|
|
31
|
-
state.error = action.payload;
|
|
32
|
-
state.status = STATUS.failure;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { delay, fork, put, race, take } from 'redux-saga/effects';
|
|
2
|
-
import { generateTakeChain, putDelayed, takeChain } from '../take-chain';
|
|
3
|
-
|
|
4
|
-
const SettlementTypes = {
|
|
5
|
-
UPDATE: 'settlement',
|
|
6
|
-
REMOVE: 'settlement',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('takeChain', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
jest.spyOn(Date, 'now').mockImplementation(() => 123);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const testTypes = [SettlementTypes.UPDATE, SettlementTypes.REMOVE];
|
|
15
|
-
const timeout = 100;
|
|
16
|
-
const testTask = jest.fn();
|
|
17
|
-
const deps: [string, number] = ['John', 23];
|
|
18
|
-
|
|
19
|
-
it('generateTakeChain few actions', () => {
|
|
20
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
21
|
-
|
|
22
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
23
|
-
|
|
24
|
-
expect(gen.next({ type: SettlementTypes.REMOVE.toString() }).value).toEqual(
|
|
25
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
expect(gen.next().value).toEqual(
|
|
29
|
-
race({
|
|
30
|
-
action: take(testTypes),
|
|
31
|
-
canceled: take('BREAK_123'),
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
expect(
|
|
35
|
-
gen.next({
|
|
36
|
-
action: { type: SettlementTypes.UPDATE.toString() },
|
|
37
|
-
canceled: { type: 'BREAK_123' },
|
|
38
|
-
}).value,
|
|
39
|
-
).toEqual(
|
|
40
|
-
fork(testTask, ...deps, [
|
|
41
|
-
{ type: SettlementTypes.REMOVE.toString() },
|
|
42
|
-
{ type: SettlementTypes.UPDATE.toString() },
|
|
43
|
-
]),
|
|
44
|
-
);
|
|
45
|
-
expect(gen.next()).toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('generateTakeChain one action', () => {
|
|
49
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
50
|
-
|
|
51
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
52
|
-
|
|
53
|
-
expect(gen.next({ type: 'settlement/REMOVE' }).value).toEqual(
|
|
54
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(gen.next().value).toEqual(
|
|
58
|
-
race({
|
|
59
|
-
action: take(testTypes),
|
|
60
|
-
canceled: take('BREAK_123'),
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
expect(
|
|
64
|
-
gen.next({
|
|
65
|
-
action: undefined,
|
|
66
|
-
canceled: { type: 'BREAK_123' },
|
|
67
|
-
}).value,
|
|
68
|
-
).toEqual(fork(testTask, ...deps, [{ type: 'settlement/REMOVE' }]));
|
|
69
|
-
expect(gen.next()).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('generateTakeChain without canceled', () => {
|
|
73
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
74
|
-
|
|
75
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
76
|
-
|
|
77
|
-
expect(gen.next({ type: 'settlement/REMOVE' }).value).toEqual(
|
|
78
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(gen.next().value).toEqual(
|
|
82
|
-
race({
|
|
83
|
-
action: take(testTypes),
|
|
84
|
-
canceled: take('BREAK_123'),
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
expect(
|
|
88
|
-
gen.next({
|
|
89
|
-
action: undefined,
|
|
90
|
-
canceled: undefined,
|
|
91
|
-
}).value,
|
|
92
|
-
).toBeTruthy();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('generateTakeChain when puts all actions and have not canceled', () => {
|
|
96
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
97
|
-
|
|
98
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
99
|
-
|
|
100
|
-
expect(gen.next({ type: SettlementTypes.REMOVE.toString() }).value).toEqual(
|
|
101
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(gen.next().value).toEqual(
|
|
105
|
-
race({
|
|
106
|
-
action: take(testTypes),
|
|
107
|
-
canceled: take('BREAK_123'),
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(
|
|
112
|
-
gen.next({
|
|
113
|
-
action: { type: SettlementTypes.UPDATE.toString() },
|
|
114
|
-
canceled: undefined,
|
|
115
|
-
}).value,
|
|
116
|
-
).toEqual(
|
|
117
|
-
fork(testTask, ...deps, [
|
|
118
|
-
{ type: SettlementTypes.REMOVE.toString() },
|
|
119
|
-
{ type: SettlementTypes.UPDATE.toString() },
|
|
120
|
-
]),
|
|
121
|
-
);
|
|
122
|
-
expect(gen.next()).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should fork generateTakeChain', () => {
|
|
126
|
-
const fakeTakeChain = takeChain(timeout, testTypes, testTask, ...deps);
|
|
127
|
-
|
|
128
|
-
expect(fakeTakeChain).toEqual(fork(generateTakeChain, timeout, testTypes, testTask, deps));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('putDelayed', () => {
|
|
133
|
-
it('should works properly', () => {
|
|
134
|
-
const gen = putDelayed(10, { type: 'test' });
|
|
135
|
-
|
|
136
|
-
expect(gen.next().value).toEqual(delay(10));
|
|
137
|
-
expect(gen.next().value).toEqual(put({ type: 'test' }));
|
|
138
|
-
|
|
139
|
-
expect(gen.next()).toBeTruthy();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Action } from '@reduxjs/toolkit';
|
|
2
|
-
import { delay, fork, put, race, take } from 'redux-saga/effects';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Накапливает экшены и генерирует эффект по таймауту.
|
|
6
|
-
* @param timeout Время задержки в мс.
|
|
7
|
-
* @param types Массив с типами ожидаемых экшенов.
|
|
8
|
-
* @param task Генератор.
|
|
9
|
-
* @param deps Аргументы для генератора.
|
|
10
|
-
* @return Эффект.
|
|
11
|
-
*/
|
|
12
|
-
export function takeChain<
|
|
13
|
-
Deps extends any[],
|
|
14
|
-
Task extends (...someArgs: [...Deps, Action[]]) => any,
|
|
15
|
-
>(timeout: number, types: string[], task: Task, ...deps: Deps) {
|
|
16
|
-
return fork(generateTakeChain as any, timeout, types, task, deps);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Генерирует эффект по таймауту.
|
|
21
|
-
* @param timeout Время задержки в мс.
|
|
22
|
-
* @param types Массив с типами ожидаемых экшенов.
|
|
23
|
-
* @param task Генератор.
|
|
24
|
-
* @param deps Аргументы для генератора.
|
|
25
|
-
*/
|
|
26
|
-
export function* generateTakeChain<
|
|
27
|
-
Deps extends any[],
|
|
28
|
-
Task extends (...someArgs: [...Deps, Action[]]) => any,
|
|
29
|
-
>(timeout: number, types: string[], task: Task, deps: Deps): Generator<any, void, any> {
|
|
30
|
-
while (true) {
|
|
31
|
-
const breakAction: Action = { type: `BREAK_${Date.now()}` };
|
|
32
|
-
const firstAction: Action = yield take(types);
|
|
33
|
-
const collectedActions = [firstAction];
|
|
34
|
-
|
|
35
|
-
yield fork(putDelayed, timeout, breakAction);
|
|
36
|
-
|
|
37
|
-
while (true) {
|
|
38
|
-
const { action, canceled } = yield race({
|
|
39
|
-
action: take(types),
|
|
40
|
-
canceled: take(breakAction.type),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
action && collectedActions.push(action);
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
canceled ||
|
|
47
|
-
types.every(type => collectedActions.some(someAction => someAction.type === type))
|
|
48
|
-
) {
|
|
49
|
-
// @todo убрать "as any"
|
|
50
|
-
yield fork(task as any, ...deps, collectedActions);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Вызывает экшен с заданной задержкой.
|
|
59
|
-
* @param timeout Время задержки в мс.
|
|
60
|
-
* @param action Тип экшена.
|
|
61
|
-
*/
|
|
62
|
-
export function* putDelayed(timeout: number, action: Action) {
|
|
63
|
-
yield delay(timeout);
|
|
64
|
-
yield put(action);
|
|
65
|
-
}
|