dry-ux 1.42.0 → 1.44.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.
- package/dist/error/ErrorBoundary.d.ts +18 -10
- package/dist/error/ErrorBoundary.js +35 -8
- package/dist/helpers/logger.d.ts +9 -0
- package/dist/helpers/logger.js +35 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
export interface IErrorBoundaryProps {
|
|
3
|
+
errorHandler?: (error?: Error, info?: React.ErrorInfo) => void;
|
|
4
|
+
onErrorCallback?: (error?: Error) => void;
|
|
5
|
+
rethrowError?: boolean;
|
|
6
|
+
fallbackUI?: React.ReactNode | ((error: Error, resetError: () => void) => JSX.Element);
|
|
7
|
+
}
|
|
8
|
+
interface IErrorBoundaryInnerState {
|
|
9
|
+
error: Error | null;
|
|
10
|
+
}
|
|
11
|
+
export declare class ErrorBoundary extends React.PureComponent<IErrorBoundaryProps, IErrorBoundaryInnerState> {
|
|
12
|
+
constructor(props: IErrorBoundaryProps);
|
|
13
|
+
static getDerivedStateFromError(error: Error): {
|
|
14
|
+
error: Error;
|
|
11
15
|
};
|
|
12
|
-
|
|
16
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
17
|
+
render: () => any;
|
|
18
|
+
private handleError;
|
|
19
|
+
private resetError;
|
|
13
20
|
}
|
|
21
|
+
export {};
|
|
@@ -3,19 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ErrorBoundary = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const ErrorScreen_1 = require("./ErrorScreen");
|
|
6
|
-
class ErrorBoundary extends React.
|
|
6
|
+
class ErrorBoundary extends React.PureComponent {
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super(props);
|
|
9
|
-
this.
|
|
9
|
+
this.render = () => {
|
|
10
|
+
const { children, fallbackUI = null } = this.props;
|
|
11
|
+
const { error } = this.state;
|
|
12
|
+
if (error) {
|
|
13
|
+
if (typeof fallbackUI === "function") {
|
|
14
|
+
return fallbackUI(error, this.resetError.bind(this));
|
|
15
|
+
}
|
|
16
|
+
return fallbackUI || React.createElement(ErrorScreen_1.ErrorScreen, null);
|
|
17
|
+
}
|
|
18
|
+
return children;
|
|
19
|
+
};
|
|
20
|
+
this.handleError = (error, info) => {
|
|
21
|
+
const { errorHandler, onErrorCallback, rethrowError } = this.props;
|
|
22
|
+
if (onErrorCallback) {
|
|
23
|
+
onErrorCallback(error);
|
|
24
|
+
}
|
|
25
|
+
if (errorHandler) {
|
|
26
|
+
errorHandler(error, info);
|
|
27
|
+
if (rethrowError) {
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (rethrowError) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.state = { error: null };
|
|
10
37
|
}
|
|
11
38
|
static getDerivedStateFromError(error) {
|
|
12
|
-
return {
|
|
39
|
+
return { error };
|
|
13
40
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
41
|
+
componentDidCatch(error, info) {
|
|
42
|
+
this.handleError(error, info);
|
|
43
|
+
}
|
|
44
|
+
resetError() {
|
|
45
|
+
this.setState({ error: null });
|
|
19
46
|
}
|
|
20
47
|
}
|
|
21
48
|
exports.ErrorBoundary = ErrorBoundary;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ILogger {
|
|
2
|
+
log(...message: string[]): void;
|
|
3
|
+
error(...message: string[]): void;
|
|
4
|
+
debug(...message: string[]): void;
|
|
5
|
+
warn(...message: string[]): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const initLoggerFactory: (path: string) => {
|
|
8
|
+
useLogger: (name: string) => ILogger;
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initLoggerFactory = void 0;
|
|
4
|
+
const useLogger = (path, name) => {
|
|
5
|
+
const convertMessage = (message) => message
|
|
6
|
+
.map(m => {
|
|
7
|
+
try {
|
|
8
|
+
if (typeof m === "string" || typeof m === "number" || typeof m === "boolean") {
|
|
9
|
+
return m.toString();
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(m);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return m;
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
.join(" ");
|
|
18
|
+
const log = (level, message) => fetch(path, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({ logger_name: name, level, message: convertMessage(message) }),
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
log: (...message) => log("info", message),
|
|
27
|
+
error: (...message) => log("error", message),
|
|
28
|
+
debug: (...message) => log("debug", message),
|
|
29
|
+
warn: (...message) => log("warn", message),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const initLoggerFactory = (path) => ({
|
|
33
|
+
useLogger: (name) => useLogger(path, name),
|
|
34
|
+
});
|
|
35
|
+
exports.initLoggerFactory = initLoggerFactory;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { Money as Money } from "./ui-utils/Money";
|
|
|
4
4
|
export * from "./ui-utils/uiUtil.interface";
|
|
5
5
|
export { DryUXProvider } from "./provider";
|
|
6
6
|
export * from "./helpers/utilities";
|
|
7
|
+
export * from "./helpers/logger";
|
|
7
8
|
export { classSet } from "./helpers/classSet";
|
|
8
9
|
export { flatten, unflatten } from "./helpers/flat";
|
|
9
10
|
export { DajaxiceProxy } from "./dajaxice/DajaxiceProxy";
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./ui-utils/uiUtil.interface"), exports);
|
|
|
26
26
|
var provider_1 = require("./provider");
|
|
27
27
|
Object.defineProperty(exports, "DryUXProvider", { enumerable: true, get: function () { return provider_1.DryUXProvider; } });
|
|
28
28
|
__exportStar(require("./helpers/utilities"), exports);
|
|
29
|
+
__exportStar(require("./helpers/logger"), exports);
|
|
29
30
|
var classSet_1 = require("./helpers/classSet");
|
|
30
31
|
Object.defineProperty(exports, "classSet", { enumerable: true, get: function () { return classSet_1.classSet; } });
|
|
31
32
|
var flat_1 = require("./helpers/flat");
|