react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / deprecated.js
81152 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule deprecated9*/1011var assign = require('Object.assign');12var warning = require('warning');1314/**15* This will log a single deprecation notice per function and forward the call16* on to the new API.17*18* @param {string} namespace The namespace of the call, eg 'React'19* @param {string} oldName The old function name, eg 'renderComponent'20* @param {string} newName The new function name, eg 'render'21* @param {*} ctx The context this forwarded call should run in22* @param {function} fn The function to forward on to23* @return {*} Will be the value as returned from `fn`24*/25function deprecated(namespace, oldName, newName, ctx, fn) {26var warned = false;27if (__DEV__) {28var newFn = function() {29warning(30warned,31`${namespace}.${oldName} will be deprecated in a future version. ` +32`Use ${namespace}.${newName} instead.`33);34warned = true;35return fn.apply(ctx, arguments);36};37newFn.displayName = `${namespace}_${oldName}`;38// We need to make sure all properties of the original fn are copied over.39// In particular, this is needed to support PropTypes40return assign(newFn, fn);41}4243return fn;44}4546module.exports = deprecated;474849