-
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-12194 Enable functional components to use consumed props #633
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
9a65f89
to
7c252f5
Compare
allPropsMixins = declaration.props.either.nodeHelper.mixins | ||
?.map<Identifier>((mixin) => mixin.name) | ||
?.toList(), |
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 think this implementation might not be correct when using the shorthand syntax, since .nodeHelper.mixins
on a mixin will be empty.
For class components, we're using allPropsMixins
, which does account for that case. Could we share that same implementation between ClassComponentDeclaration
and PropsMapViewOrFunctionComponentDeclaration
so that we can use it here as well?
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.
Definitely, good catch. Updated in ea0e4aa!
lib/src/builder/codegen/util.dart
Outdated
buffer | ||
..writeln() | ||
..writeln(' @override') | ||
..writeln(' $classType get $fieldName => ${isConst ? 'const' : ''} $classType({'); |
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.
Why is the instance conditionally const? Can't it always be const?
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 might be missing something, but not with the current implementation of InstancePropsMeta
because it has instance fields. If I change that to not keep that state though, then that will clean this up as well!
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.
Updated this in ea0e4aa!
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.
Noticed a couple things but this generally looks great!
@@ -75,6 +76,9 @@ Map getPropsToForward(Map props, { | |||
/// | |||
/// Based upon configuration, the function will overlook [props] that are not | |||
/// meant to be passed on, such as non-DOM props or specified values. | |||
/// | |||
/// DEPRECATED: Use [forwardUnconsumedPropsV2] instead. | |||
@Deprecated('This implementation does not filter DOM props correctly. Use forwardUnconsumedPropsV2 instead.') |
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.
👏
lib/src/util/react_util.dart
Outdated
@@ -40,6 +40,8 @@ class UiPropsMapView extends MapView | |||
bool get $isClassGenerated => | |||
throw UnimplementedError('@PropsMixin instances do not implement \$isClassGenerated'); | |||
|
|||
PropsMetaCollection get $meta => throw UnimplementedError('@PropsMixin instances do not implement instance meta'); |
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.
Unrelated to this PR, but we should really deprecate the UiPropsMapView
class... It's made obsolete by the new boilerplate for props map views, which are real UiProps
classes
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.
:noice: Updated in 88e20b7!
728f513
to
7f801fa
Compare
/// | ||
/// This is useful in conjunction with [UiProps]'s `addUnconsumedProps`, | ||
/// which expects [PropsMeta] to be provided in a [List]. | ||
List<PropsMeta> inList() => [this]; |
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.
Added this because of this
'prop 5': 'my prop #5', | ||
'prop 6': 'my prop #6', | ||
}, keySetsToOmit: [], propsToUpdate: actual); | ||
test('when keySetsToOmit is null', () { |
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.
This is the only new test in this function
'ref': 'my ref', | ||
'other prop': 'my other prop' | ||
}; | ||
void commonPropsForwardingUtilTests(ForwardUnconsumedPropsFunction functionToTest) { |
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 tests (in commonPropsForwardingUtilTests
) were all here originally - except for one, which is noted below.
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.
Found a couple things, but this is looking great; should be my final pass!
...component_declaration/builder_integration_tests/new_boilerplate/function_component_test.dart
Outdated
Show resolved
Hide resolved
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.
Just one more small comment
QA +1 |
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.
+1
This looks awesome @joebingham-wk !!!
@Workiva/release-management-p |
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.
+1 from RM
Motivation
In class based components, we have the API's
addUnconsumedProps
to facilitate passing along props more easily. We want the same behavior in functional components.Changes
PropsInstanceMeta
) that uses a mixin onPropsMetaCollection
to manage consumed props operations (e0cde45)UiProps
called$meta
typed asPropsInstanceMeta
(e0cde45)UiPropsMeta
) onUiProps
that can be used to access$meta
, along with adding APIs to derive consumed props (e0cde45)STILL LEFT TO DO:
Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
@aaronlademann-wf @greglittlefield-wf @sydneyjodon-wk
QA Checklist
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: