mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
b77b12311f
* Call and Return components should use ReactElement ReactChildFiber contains lots of branches that do the same thing for different child types. We can unify them by having more child types be ReactElements. This requires that the `type` and `key` fields are sufficient to determine the identity of the child. The main benefit is decreased file size, especially as we add more component types, like context providers and consumers. This updates Call and Return components to use ReactElement. Portals are left alone for now because their identity includes the host instance. * Move server render invariant for call and return types * Sort ReactElement type checks by most likely * Performance timeline should skip over call components Don't think these were intentionally omitted from the blacklist of component types. I went ahead and updated getComponentName to include special types, even though I don't think they're used anywhere right now. * Remove surrounding brackets from internal display names
96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2014-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
|
|
*/
|
|
|
|
import {
|
|
REACT_CALL_TYPE,
|
|
REACT_RETURN_TYPE,
|
|
REACT_ELEMENT_TYPE,
|
|
} from 'shared/ReactSymbols';
|
|
|
|
import type {ReactCall, ReactNodeList, ReactReturn} from 'shared/ReactTypes';
|
|
|
|
type CallHandler<T, V> = (props: T, returns: Array<V>) => ReactNodeList;
|
|
|
|
export function unstable_createCall<T, V>(
|
|
children: ReactNodeList,
|
|
handler: CallHandler<T, V>,
|
|
props: T,
|
|
key: ?string = null,
|
|
): ReactCall<V> {
|
|
const call = {
|
|
// This tag allow us to uniquely identify this as a React Call
|
|
$$typeof: REACT_ELEMENT_TYPE,
|
|
type: REACT_CALL_TYPE,
|
|
key: key == null ? null : '' + key,
|
|
ref: null,
|
|
props: {
|
|
props,
|
|
handler,
|
|
children: children,
|
|
},
|
|
};
|
|
|
|
if (__DEV__) {
|
|
// TODO: Add _store property for marking this as validated.
|
|
if (Object.freeze) {
|
|
Object.freeze(call.props);
|
|
Object.freeze(call);
|
|
}
|
|
}
|
|
|
|
return call;
|
|
}
|
|
|
|
export function unstable_createReturn<V>(value: V): ReactReturn<V> {
|
|
const returnNode = {
|
|
// This tag allow us to uniquely identify this as a React Call
|
|
$$typeof: REACT_ELEMENT_TYPE,
|
|
type: REACT_RETURN_TYPE,
|
|
key: null,
|
|
ref: null,
|
|
props: {
|
|
value,
|
|
},
|
|
};
|
|
|
|
if (__DEV__) {
|
|
// TODO: Add _store property for marking this as validated.
|
|
if (Object.freeze) {
|
|
Object.freeze(returnNode);
|
|
}
|
|
}
|
|
|
|
return returnNode;
|
|
}
|
|
|
|
/**
|
|
* Verifies the object is a call object.
|
|
*/
|
|
export function unstable_isCall(object: mixed): boolean {
|
|
return (
|
|
typeof object === 'object' &&
|
|
object !== null &&
|
|
object.type === REACT_CALL_TYPE
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Verifies the object is a return object.
|
|
*/
|
|
export function unstable_isReturn(object: mixed): boolean {
|
|
return (
|
|
typeof object === 'object' &&
|
|
object !== null &&
|
|
object.type === REACT_RETURN_TYPE
|
|
);
|
|
}
|
|
|
|
export const unstable_REACT_RETURN_TYPE = REACT_RETURN_TYPE;
|
|
export const unstable_REACT_CALL_TYPE = REACT_CALL_TYPE;
|