Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Add support for React.memo
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Oct 29, 2018
1 parent 0c2d825 commit 4d85b12
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions backend/attachRendererFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ function getInternalReactConstants(version) {
CONTEXT_PROVIDER_SYMBOL_STRING: 'Symbol(react.provider)',
FORWARD_REF_NUMBER: 0xead0,
FORWARD_REF_SYMBOL_STRING: 'Symbol(react.forward_ref)',
MEMO_NUMBER: 0xead3,
MEMO_SYMBOL_STRING: 'Symbol(react.memo)',
PROFILER_NUMBER: 0xead2,
PROFILER_SYMBOL_STRING: 'Symbol(react.profiler)',
PURE_NUMBER: 0xead3,
PURE_SYMBOL_STRING: 'Symbol(react.pure)',
STRICT_MODE_NUMBER: 0xeacc,
STRICT_MODE_SYMBOL_STRING: 'Symbol(react.strict_mode)',
SUSPENSE_NUMBER: 0xead1,
Expand Down Expand Up @@ -143,6 +143,8 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
HostText,
Fragment,
ForwardRef,
MemoComponent,
SimpleMemoComponent,
} = ReactTypeOfWork;
var {
CONCURRENT_MODE_NUMBER,
Expand All @@ -154,8 +156,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
CONTEXT_PROVIDER_SYMBOL_STRING,
PROFILER_NUMBER,
PROFILER_SYMBOL_STRING,
PURE_NUMBER,
PURE_SYMBOL_STRING,
STRICT_MODE_NUMBER,
STRICT_MODE_SYMBOL_STRING,
SUSPENSE_NUMBER,
Expand All @@ -166,6 +166,7 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
// TODO: we might want to change the data structure
// once we no longer suppport Stack versions of `getData`.
function getDataFiber(fiber: Object): DataType {
var elementType = fiber.elementType;
var type = fiber.type;
var key = fiber.key;
var ref = fiber.ref;
Expand Down Expand Up @@ -279,6 +280,17 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
nodeType = 'Wrapper';
children = [];
break;
case MemoComponent:
case SimpleMemoComponent:
nodeType = 'Special';
if (elementType.displayName) {
name = elementType.displayName;
} else {
const displayName = type.displayName || type.name;
name = displayName ? `Memo(${displayName})` : 'Memo';
}
children = [];
break;
default:
const symbolOrNumber = typeof type === 'object' && type !== null
? type.$$typeof
Expand All @@ -289,17 +301,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
: symbolOrNumber;

switch (switchValue) {
case PURE_NUMBER:
case PURE_SYMBOL_STRING:
nodeType = 'Special';
if (type.displayName) {
name = type.displayName;
} else {
const displayName = type.render.displayName || type.render.name;
name = displayName ? `Pure(${displayName})` : 'Pure';
}
children = [];
break;
case CONCURRENT_MODE_NUMBER:
case CONCURRENT_MODE_SYMBOL_STRING:
case DEPRECATED_ASYNC_MODE_SYMBOL_STRING:
Expand Down

0 comments on commit 4d85b12

Please sign in to comment.