You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
480 B
24 lines
480 B
6 years ago
|
export function availableReporter(
|
||
|
positiveMsg: string|null,
|
||
|
negativeMsg: string|null,
|
||
|
positiveAction = console.log,
|
||
|
negativeAction = console.error,
|
||
|
) {
|
||
|
let reported = false;
|
||
|
return available => {
|
||
|
if(available && reported) {
|
||
|
reported = false;
|
||
|
if(positiveMsg) {
|
||
|
positiveAction(positiveMsg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(!available && !reported) {
|
||
|
reported = true;
|
||
|
if(negativeMsg) {
|
||
|
negativeAction(negativeMsg);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|