-
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
AF-392: Add workaround to NSM for Dart 2 #207
Changes from 1 commit
d0a3cb7
eeb947c
2e1cb13
7f6be51
34fa0b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,30 +636,49 @@ abstract class UiProps extends MapBase | |
/// | ||
/// Restricted statically to 40 arguments until the dart2js fix in | ||
/// <https://github.com/dart-lang/sdk/pull/26032> is released. | ||
ReactElement call([children, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40]); | ||
/// | ||
ReactElement call([c1 = _notSpecified, c2 = _notSpecified, c3 = _notSpecified, c4 = _notSpecified, c5 = _notSpecified, c6 = _notSpecified, c7 = _notSpecified, c8 = _notSpecified, c9 = _notSpecified, c10 = _notSpecified, c11 = _notSpecified, c12 = _notSpecified, c13 = _notSpecified, c14 = _notSpecified, c15 = _notSpecified, c16 = _notSpecified, c17 = _notSpecified, c18 = _notSpecified, c19 = _notSpecified, c20 = _notSpecified, c21 = _notSpecified, c22 = _notSpecified, c23 = _notSpecified, c24 = _notSpecified, c25 = _notSpecified, c26 = _notSpecified, c27 = _notSpecified, c28 = _notSpecified, c29 = _notSpecified, c30 = _notSpecified, c31 = _notSpecified, c32 = _notSpecified, c33 = _notSpecified, c34 = _notSpecified, c35 = _notSpecified, c36 = _notSpecified, c37 = _notSpecified, c38 = _notSpecified, c39 = _notSpecified, c40 = _notSpecified]) { | ||
List childArguments; | ||
// Use `identical` since it compiles down to `===` in dart2js instead of calling equality helper functions, | ||
// and we don't want to allow any object overriding `operator==` to claim it's equal to `_notSpecified`. | ||
if (identical(c1, _notSpecified)) { | ||
corwinsheahan-wf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
childArguments = []; | ||
} else if (identical(c2, _notSpecified)) { | ||
childArguments = [c1]; | ||
} else if (identical(c3, _notSpecified)) { | ||
childArguments = [c1, c2]; | ||
} else if (identical(c4, _notSpecified)) { | ||
childArguments = [c1, c2, c3]; | ||
} else if (identical(c5, _notSpecified)) { | ||
childArguments = [c1, c2, c3, c4]; | ||
} else if (identical(c6, _notSpecified)) { | ||
childArguments = [c1, c2, c3, c4, c5]; | ||
greglittlefield-wf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else if (identical(c7, _notSpecified)) { | ||
childArguments = [c1, c2, c3, c4, c5, c6]; | ||
} else { | ||
childArguments = [c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40] | ||
.takeWhile((child) => !identical(child, _notSpecified)) | ||
.toList(); | ||
} | ||
|
||
/// Supports variadic children of the form `call([child1, child2, child3...])`. | ||
@override | ||
dynamic noSuchMethod(Invocation invocation) { | ||
if (invocation.memberName == #call && invocation.isMethod) { | ||
final positionalArguments = invocation.positionalArguments; | ||
assert(_validateChildren(positionalArguments.length == 1 ? positionalArguments.single : positionalArguments)); | ||
|
||
final factory = componentFactory; | ||
if (factory is ReactComponentFactoryProxy) { | ||
// Use `build` instead of using emulated function behavior to work around DDC issue | ||
// https://github.com/dart-lang/sdk/issues/29904 | ||
// Should have the benefit of better performance; TODO optimize type check? | ||
// ignore: avoid_as | ||
return factory.build(props, invocation.positionalArguments); | ||
} else { | ||
var parameters = [] | ||
..add(props) | ||
..addAll(invocation.positionalArguments); | ||
return Function.apply(factory, parameters); | ||
} | ||
assert(_validateChildren(childArguments.length == 1 ? childArguments.single : childArguments)); | ||
|
||
final factory = componentFactory; | ||
if (factory is ReactComponentFactoryProxy) { | ||
// Use `build` instead of using emulated function behavior to work around DDC issue | ||
// https://github.com/dart-lang/sdk/issues/29904 | ||
// Should have the benefit of better performance; TODO optimize type check? | ||
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 TODO was already in the 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. Hm, looking at this again, this type-check should be quite cheap, so I say we can remove this TODO |
||
return factory.build(props, childArguments); | ||
} else { | ||
var parameters = [] | ||
..add(props) | ||
..addAll(childArguments); | ||
return Function.apply(factory, parameters); | ||
} | ||
} | ||
|
||
@override | ||
dynamic noSuchMethod(Invocation invocation) { | ||
corwinsheahan-wf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return super.noSuchMethod(invocation); | ||
} | ||
|
||
|
@@ -809,3 +828,8 @@ class ConsumedProps { | |
|
||
const ConsumedProps(this.props, this.keys); | ||
} | ||
|
||
const _notSpecified = const NotSpecified(); | ||
class NotSpecified { | ||
const NotSpecified(); | ||
} |
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.
These can actually just get removed now, since they were put in as a workaround to not having NSM! a5c1820#diff-f41fd818c60cfc37d947e71aa885a019
🎉