Skip to content

Commit 4b4049c

Browse files
authored
Add error support to LogService (#2025)
1 parent 1a13fdc commit 4b4049c

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/services/LogService.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,46 @@ function warn(message: string) {
44
}
55
}
66

7-
function deprecationWarn({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
7+
function error(message: string) {
8+
if (__DEV__) {
9+
console.error(message);
10+
}
11+
}
12+
13+
function getDeprecationMessage({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
814
const message = newProp
915
? `RNUILib's ${component} "${oldProp}" prop will be deprecated soon, please use the "${newProp}" prop instead`
1016
: `RNUILib's ${component} "${oldProp}" prop will be deprecated soon, please stop using it`;
11-
warn(message);
17+
return message;
1218
}
1319

14-
function componentDeprecationWarn({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
20+
function getComponentDeprecationMessage({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
1521
const message = `RNUILib's ${oldComponent} component will be deprecated soon, please use the "${newComponent}" component instead`;
1622

17-
warn(message);
23+
return message;
24+
}
25+
26+
function deprecationWarn({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
27+
warn(getDeprecationMessage({component, oldProp, newProp}));
28+
}
29+
30+
function componentDeprecationWarn({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
31+
warn(getComponentDeprecationMessage({oldComponent, newComponent}));
32+
}
33+
34+
function deprecationError({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
35+
error(getDeprecationMessage({component, oldProp, newProp}));
36+
}
37+
38+
function componentDeprecationError({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
39+
error(getComponentDeprecationMessage({oldComponent, newComponent}));
1840
}
1941

2042
export default {
2143
warn,
44+
error,
2245
deprecationWarn,
23-
componentDeprecationWarn
46+
componentDeprecationWarn,
47+
deprecationError,
48+
componentDeprecationError
2449
};

0 commit comments

Comments
 (0)