-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPLAT-11977 Consume/update typing for forwardRef2/memo2 functions #620
Changes from all commits
e368225
1fb6edd
871c9c7
73beab1
85c2690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,7 +470,7 @@ void useLayoutEffect(dynamic Function() sideEffect, [List<Object> dependencies]) | |
/// ``` | ||
/// | ||
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#useimperativehandle>. | ||
void useImperativeHandle(Ref ref, dynamic Function() createHandle, [List<dynamic> dependencies]) => | ||
void useImperativeHandle(dynamic ref, dynamic Function() createHandle, [List<dynamic> dependencies]) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has just been updated to match the typing of the react-dart version |
||
react_hooks.useImperativeHandle(ref, createHandle, dependencies); | ||
|
||
/// Displays [value] as a label for a custom hook in React DevTools. | ||
|
@@ -544,4 +544,4 @@ void useImperativeHandle(Ref ref, dynamic Function() createHandle, [List<dynamic | |
/// ``` | ||
/// | ||
/// Learn more: <https://reactjs.org/docs/hooks-reference.html#usedebugvalue>. | ||
dynamic useDebugValue<T>(T value, [dynamic Function(T) format]) => react_hooks.useDebugValue(value, format); | ||
dynamic useDebugValue<T>(T value, [dynamic Function(T) format]) => react_hooks.useDebugValue(value, format); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,15 +412,10 @@ UiFactory<TProps> uiForwardRef<TProps extends bh.UiProps>( | |
return functionComponent(propsFactory.jsMap(props), ref); | ||
} | ||
|
||
ReactJsComponentFactoryProxy factory; | ||
|
||
// If a consumer uses `asForwardRefConfig` to generate the function component | ||
// config, displayName could be `null` or an empty string. | ||
if (displayName != null && displayName.isNotEmpty) { | ||
factory = react_interop.forwardRef(_uiFunctionWrapper, displayName: displayName); | ||
} else { | ||
factory = react_interop.forwardRef(_uiFunctionWrapper); | ||
} | ||
// Always pass displayName, even if it's empty, | ||
// since we don't want forwardRef2 to use _uiFunctionWrapper as the name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under the hood forwardRef2 falls back to the name of the function if If the name is empty, it will still show up as "Anonymous" in the dev tools, so functionality is equivalent. |
||
final factory = | ||
react_interop.forwardRef2(_uiFunctionWrapper, displayName: displayName); | ||
|
||
if (propsFactory == null) { | ||
if (TProps != UiProps && TProps != GenericUiProps) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ main() { | |
final Ref refObject = createRef(); | ||
final vDomElement = (BasicForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'Anonymous'); | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
|
||
test('when displayName argument is passed to the config constructor', () { | ||
|
@@ -71,7 +71,7 @@ main() { | |
final Ref refObject = createRef(); | ||
final vDomElement = (BasicForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName); | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), displayName); | ||
}); | ||
|
||
group('returns normally when passed children', () { | ||
|
@@ -99,7 +99,7 @@ main() { | |
final Ref refObject = createRef(); | ||
final vDomElement = (TopLevelForwardUiRefFunction()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), | ||
'TopLevelForwardUiRefFunction'); | ||
}); | ||
|
||
|
@@ -153,7 +153,7 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) { | |
UiFactory<DomProps> getFactoryForDiv({ | ||
String displayName, | ||
}) { | ||
ReactElement div(Ref ref, dynamic children) => (Dom.div()..ref = ref)(children); | ||
ReactElement div(dynamic ref, dynamic children) => (Dom.div()..ref = ref)(children); | ||
|
||
if (useUiForwardRef) { | ||
if (displayName == null) { | ||
|
@@ -201,8 +201,11 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) { | |
final refObject = createRef<DivElement>(); | ||
final vDomElement = (DivForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), | ||
useUiForwardRef ? 'Anonymous' : 'div'); | ||
if (useUiForwardRef) { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), ''); | ||
} else { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'div'); | ||
} | ||
}); | ||
|
||
test('when displayName argument is passed to the config constructor', () { | ||
|
@@ -211,7 +214,12 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) { | |
final refObject = createRef<DivElement>(); | ||
final vDomElement = (DivForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName); | ||
|
||
if (useUiForwardRef) { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), displayName); | ||
} else { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName); | ||
} | ||
}); | ||
}); | ||
|
||
|
@@ -238,8 +246,11 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) { | |
final Ref refObject = createRef(); | ||
final vDomElement = (BasicForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), | ||
useUiForwardRef ? 'Anonymous' : 'Basic'); | ||
if (useUiForwardRef) { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), ''); | ||
} else { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'Basic'); | ||
} | ||
}); | ||
|
||
test('when displayName argument is passed to the config constructor', () { | ||
|
@@ -248,7 +259,11 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) { | |
final Ref refObject = createRef(); | ||
final vDomElement = (BasicForwarded()..ref = refObject)(); | ||
|
||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName); | ||
if (useUiForwardRef) { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'name'), displayName); | ||
} else { | ||
expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName); | ||
} | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified this while i was in here fixing the typing on
forwardedRef