mirror of
https://github.com/facebook/react.git
synced 2026-02-26 06:35:39 +00:00
* Use relative paths in packages/react * Use relative paths in packages/react-art * Use relative paths in packages/react-cs * Use relative paths in other packages * Fix as many issues as I can This uncovered an interesting problem where ./b from package/src/a would resolve to a different instantiation of package/src/b in Jest. Either this is a showstopper or we can solve it by completely fobbidding remaining /src/. * Fix all tests It seems we can't use relative requires in tests anymore. Otherwise Jest becomes confused between real file and symlink. https://github.com/facebook/jest/issues/3830 This seems bad... Except that we already *don't* want people to create tests that import individual source files. All existing cases of us doing so are actually TODOs waiting to be fixed. So perhaps this requirement isn't too bad because it makes bad code looks bad. Of course, if we go with this, we'll have to lint against relative requires in tests. It also makes moving things more painful. * Prettier * Remove @providesModule * Fix remaining Haste imports I missed earlier * Fix up paths to reflect new flat structure * Fix Flow * Fix CJS and UMD builds * Fix FB bundles * Fix RN bundles * Prettier * Fix lint * Fix warning printing and error codes * Fix buggy return * Fix lint and Flow * Use Yarn on CI * Unbreak Jest * Fix lint * Fix aliased originals getting included in DEV Shouldn't affect correctness (they were ignored) but fixes DEV size regression. * Record sizes * Fix weird version in package.json * Tweak bundle labels * Get rid of output option by introducing react-dom/server.node * Reconciler should depend on prop-types * Update sizes last time
80 lines
2.2 KiB
JavaScript
80 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
/**
|
|
* In the future, we should cleanup callbacks by cancelling them instead of
|
|
* using this.
|
|
*/
|
|
function mountSafeCallback(context: any, callback: ?Function): any {
|
|
return function() {
|
|
if (!callback) {
|
|
return undefined;
|
|
}
|
|
if (typeof context.__isMounted === 'boolean') {
|
|
// TODO(gaearon): this is gross and should be removed.
|
|
// It is currently necessary because View uses createClass,
|
|
// and so any measure() calls on View (which are done by React
|
|
// DevTools) trigger the isMounted() deprecation warning.
|
|
if (!context.__isMounted) {
|
|
return undefined;
|
|
}
|
|
// The else branch is important so that we don't
|
|
// trigger the deprecation warning by calling isMounted.
|
|
} else if (typeof context.isMounted === 'function') {
|
|
if (!context.isMounted()) {
|
|
return undefined;
|
|
}
|
|
}
|
|
return callback.apply(context, arguments);
|
|
};
|
|
}
|
|
|
|
function throwOnStylesProp(component: any, props: any) {
|
|
if (props.styles !== undefined) {
|
|
var owner = component._owner || null;
|
|
var name = component.constructor.displayName;
|
|
var msg =
|
|
'`styles` is not a supported property of `' +
|
|
name +
|
|
'`, did ' +
|
|
'you mean `style` (singular)?';
|
|
if (owner && owner.constructor && owner.constructor.displayName) {
|
|
msg +=
|
|
'\n\nCheck the `' +
|
|
owner.constructor.displayName +
|
|
'` parent ' +
|
|
' component.';
|
|
}
|
|
throw new Error(msg);
|
|
}
|
|
}
|
|
|
|
function warnForStyleProps(props: any, validAttributes: any) {
|
|
for (var key in validAttributes.style) {
|
|
if (!(validAttributes[key] || props[key] === undefined)) {
|
|
console.error(
|
|
'You are setting the style `{ ' +
|
|
key +
|
|
': ... }` as a prop. You ' +
|
|
'should nest it in a style object. ' +
|
|
'E.g. `{ style: { ' +
|
|
key +
|
|
': ... } }`',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
mountSafeCallback,
|
|
throwOnStylesProp,
|
|
warnForStyleProps,
|
|
};
|