Skip to content

Commit

Permalink
chore(ts): migrate "logger" (#4132)
Browse files Browse the repository at this point in the history
* chore(ts): migrate "logger"

Had to cast the warning, see https://stackoverflow.com/a/48675307 for a similar question.

* no cache on noop

* Update src/lib/utils/logger.ts

* chore: move stuff around
  • Loading branch information
Haroenv committed Oct 23, 2019
1 parent d888f41 commit 437a4c4
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/lib/utils/logger.js → src/lib/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import noop from './noop';

let deprecate = noop;
let warn = noop;
type Deprecate<TCallback = (...args: any[]) => any> = (
fn: TCallback,
message: string
) => TCallback;

type Warn = (message: string) => void;

type Warning = {
(condition: boolean, message: string): void;
cache: { [message: string]: boolean };
};

/**
* Logs a warning when this function is called, in development environment only.
*/
let deprecate: Deprecate = fn => fn;

/**
* Logs a warning
* This is used to log issues in development environment only.
*/
let warn: Warn = noop;

/**
* Logs a warning if the condition is not met.
* This is used to log issues in development environment only.
*
* @returns {undefined}
*/
let warning = noop;
let warning = noop as Warning;

if (__DEV__) {
warn = message => {
Expand All @@ -31,7 +49,7 @@ if (__DEV__) {
};
};

warning = (condition, message) => {
warning = ((condition, message) => {
if (condition) {
return;
}
Expand All @@ -43,7 +61,7 @@ if (__DEV__) {

warn(message);
}
};
}) as Warning;

warning.cache = {};
}
Expand Down

0 comments on commit 437a4c4

Please sign in to comment.