Skip to content

Commit

Permalink
Create two React objects with the condition of hooks enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Nov 20, 2018
1 parent bad3cd1 commit b3d5af0
Showing 1 changed file with 103 additions and 53 deletions.
156 changes: 103 additions & 53 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,57 +50,107 @@ import {enableStableConcurrentModeAPIs} from 'shared/ReactFeatureFlags';

// Please make sure that no properties are added to this object after its
// creation. This ensures the object keeps the same shape for performance reasons.
export default {
Children: {
map,
forEach,
count,
toArray,
only,
},
let React;
// We should remove the need for two objects if hooks are enabled by default.
if (enableHooks) {
React = {
Children: {
map,
forEach,
count,
toArray,
only,
},

createRef,
Component,
PureComponent,

createContext,
forwardRef,
lazy,
memo,

Fragment: REACT_FRAGMENT_TYPE,
StrictMode: REACT_STRICT_MODE_TYPE,
Suspense: REACT_SUSPENSE_TYPE,

createElement: __DEV__ ? createElementWithValidation : createElement,
cloneElement: __DEV__ ? cloneElementWithValidation : cloneElement,
createFactory: __DEV__ ? createFactoryWithValidation : createFactory,
isValidElement: isValidElement,

version: ReactVersion,

__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals,

ConcurrentMode: enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
Profiler: enableStableConcurrentModeAPIs ? REACT_PROFILER_TYPE : null,

unstable_ConcurrentMode: !enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
unstable_Profiler: !enableStableConcurrentModeAPIs
? REACT_PROFILER_TYPE
: null,

useCallback,
useContext,
useEffect,
useImperativeMethods,
useLayoutEffect,
useMemo,
useMutationEffect,
useReducer,
useRef,
useState,
};
} else {
React = {
Children: {
map,
forEach,
count,
toArray,
only,
},

createRef,
Component,
PureComponent,

createContext,
forwardRef,
lazy,
memo,

Fragment: REACT_FRAGMENT_TYPE,
StrictMode: REACT_STRICT_MODE_TYPE,
Suspense: REACT_SUSPENSE_TYPE,

createElement: __DEV__ ? createElementWithValidation : createElement,
cloneElement: __DEV__ ? cloneElementWithValidation : cloneElement,
createFactory: __DEV__ ? createFactoryWithValidation : createFactory,
isValidElement: isValidElement,

version: ReactVersion,

__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals,

ConcurrentMode: enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
Profiler: enableStableConcurrentModeAPIs ? REACT_PROFILER_TYPE : null,

unstable_ConcurrentMode: !enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
unstable_Profiler: !enableStableConcurrentModeAPIs
? REACT_PROFILER_TYPE
: null,
};
}

createRef,
Component,
PureComponent,

createContext,
forwardRef,
lazy,
memo,

Fragment: REACT_FRAGMENT_TYPE,
StrictMode: REACT_STRICT_MODE_TYPE,
Suspense: REACT_SUSPENSE_TYPE,

createElement: __DEV__ ? createElementWithValidation : createElement,
cloneElement: __DEV__ ? cloneElementWithValidation : cloneElement,
createFactory: __DEV__ ? createFactoryWithValidation : createFactory,
isValidElement: isValidElement,

version: ReactVersion,

__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals,

ConcurrentMode: enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
Profiler: enableStableConcurrentModeAPIs ? REACT_PROFILER_TYPE : null,

unstable_ConcurrentMode: !enableStableConcurrentModeAPIs
? REACT_CONCURRENT_MODE_TYPE
: null,
unstable_Profiler: !enableStableConcurrentModeAPIs
? REACT_PROFILER_TYPE
: null,

useCallback: enableHooks ? useCallback : null,
useContext: enableHooks ? useContext : null,
useEffect: enableHooks ? useEffect : null,
useImperativeMethods: enableHooks ? useImperativeMethods : null,
useLayoutEffect: enableHooks ? useLayoutEffect : null,
useMemo: enableHooks ? useMemo : null,
useMutationEffect: enableHooks ? useMutationEffect : null,
useReducer: enableHooks ? useReducer : null,
useRef: enableHooks ? useRef : null,
useState: enableHooks ? useState : null,
};
export default React;

0 comments on commit b3d5af0

Please sign in to comment.