Skip to content

Add error support to LogService #2025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/services/LogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,46 @@ function warn(message: string) {
}
}

function deprecationWarn({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
function error(message: string) {
if (__DEV__) {
console.error(message);
}
}

function getDeprecationMessage({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
const message = newProp
? `RNUILib's ${component} "${oldProp}" prop will be deprecated soon, please use the "${newProp}" prop instead`
: `RNUILib's ${component} "${oldProp}" prop will be deprecated soon, please stop using it`;
warn(message);
return message;
}

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

warn(message);
return message;
}

function deprecationWarn({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
warn(getDeprecationMessage({component, oldProp, newProp}));
}

function componentDeprecationWarn({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
warn(getComponentDeprecationMessage({oldComponent, newComponent}));
}

function deprecationError({component, oldProp, newProp}: {component: string; oldProp: string; newProp?: string}) {
error(getDeprecationMessage({component, oldProp, newProp}));
}

function componentDeprecationError({oldComponent, newComponent}: {oldComponent: string; newComponent: string}) {
error(getComponentDeprecationMessage({oldComponent, newComponent}));
}

export default {
warn,
error,
deprecationWarn,
componentDeprecationWarn
componentDeprecationWarn,
deprecationError,
componentDeprecationError
};