Skip to content

Commit

Permalink
Make warnMoved a more generic function
Browse files Browse the repository at this point in the history
  • Loading branch information
empyrical committed Feb 4, 2019
1 parent c212a1f commit 39fe07c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 64 deletions.
43 changes: 0 additions & 43 deletions Libraries/Utilities/warnMoved.js

This file was deleted.

34 changes: 34 additions & 0 deletions Libraries/Utilities/warnOnce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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;
38 changes: 17 additions & 21 deletions Libraries/react-native/react-native-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
'use strict';

const invariant = require('invariant');
const warnMoved = require('warnMoved');

let showedListViewDeprecation = false;
let showedSwipeableListViewDeprecation = false;
const warnOnce = require('warnOnce');

// Export React, plus some native additions.
module.exports = {
Expand Down Expand Up @@ -62,14 +59,11 @@ module.exports = {
return require('KeyboardAvoidingView');
},
get ListView() {
if (!showedListViewDeprecation) {
console.warn(
'ListView is deprecated and will be removed in a future release. ' +
'See https://fb.me/nolistview for more information',
);

showedListViewDeprecation = true;
}
warnOnce(
'listview-deprecation',
'ListView is deprecated and will be removed in a future release. ' +
'See https://fb.me/nolistview for more information',
);
return require('ListView');
},
get MaskedViewIOS() {
Expand Down Expand Up @@ -121,14 +115,11 @@ module.exports = {
return require('SwipeableFlatList');
},
get SwipeableListView() {
if (!showedSwipeableListViewDeprecation) {
console.warn(
'ListView and SwipeableListView are deprecated and will be removed in a future release. ' +
'See https://fb.me/nolistview for more information',
);

showedSwipeableListViewDeprecation = true;
}
warnOnce(
'swipablelistview-deprecation',
'ListView and SwipeableListView are deprecated and will be removed in a future release. ' +
'See https://fb.me/nolistview for more information',
);
return require('SwipeableListView');
},
get Text() {
Expand Down Expand Up @@ -165,7 +156,12 @@ module.exports = {
return require('VirtualizedList');
},
get WebView() {
warnMoved('WebView', 'react-native-webview');
warnOnce(
'webview-moved',
'WebView has been extracted from react-native core and will be removed in a future release. ' +
"It can now be installed and imported from 'react-native-webview' instead of 'react-native'. " +
'See https://github.com/react-native-community/react-native-webview for more informations.',
);
return require('WebView');
},

Expand Down

0 comments on commit 39fe07c

Please sign in to comment.