mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: This pull request adds a function called `warnOnce` that prints a warning message to the console once per session. It uses a unique key per callsite to help ensure that the message is not printed multiple times. [General] [Added] - Added new `warnOnce` function for printing a message to the developer console once per session [General] [Changed] - Changed the warnings in `react-native-implementation` to use `warnOnce` Pull Request resolved: https://github.com/facebook/react-native/pull/22109 Differential Revision: D13955887 Pulled By: cpojer fbshipit-source-id: aa51ac427a80cc0554a6bcc915715821d0bd5439
35 lines
766 B
JavaScript
35 lines
766 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const warning = require('fbjs/lib/warning');
|
|
|
|
const warnedKeys: {[string]: boolean} = {};
|
|
|
|
/**
|
|
* A simple function that prints a warning message once per session.
|
|
*
|
|
* @param {string} key - The key used to ensure the message is printed once.
|
|
* This should be unique to the callsite.
|
|
* @param {string} message - The message to print
|
|
*/
|
|
function warnOnce(key: string, message: string) {
|
|
if (warnedKeys[key]) {
|
|
return;
|
|
}
|
|
|
|
warning(false, message);
|
|
|
|
warnedKeys[key] = true;
|
|
}
|
|
|
|
module.exports = warnOnce;
|