Skip to content
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

Merged
merged 24 commits into from
Oct 26, 2020

Conversation

joebingham-wk
Copy link
Contributor

@joebingham-wk joebingham-wk commented Oct 9, 2020

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

  • Create a new class (PropsInstanceMeta) that uses a mixin on PropsMetaCollection to manage consumed props operations (e0cde45)
  • Add a property onto UiProps called $meta typed as PropsInstanceMeta (e0cde45)
  • Update the builder to override the field on Component2 / functional component props instances (8855f7e)
  • Add a mixin (UiPropsMeta) on UiProps that can be used to access $meta, along with adding APIs to derive consumed props (e0cde45)
  • Add examples (51b5466)

STILL LEFT TO DO:

  • Receive feedback on the approach thus far
  • Add doc comments / documentation
  • Add tests

Release Notes

  • Add APIs for using consumed props in functional components

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

  • Tests were updated and provide good coverage of the changeset and other affected code
  • Manual testing was performed if needed

Merge Checklist

While we perform many automated checks before auto-merging, some manual checks are needed:

  • A Client Platform member has reviewed these changes
  • There are no unaddressed comments - this check can be automated if reviewers use the "Request Changes" feature
  • For release PRs - Version metadata in Rosie comment is correct

@aviary-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@joebingham-wk joebingham-wk force-pushed the CPLAT-12194-functional-consumed-props branch from 9a65f89 to 7c252f5 Compare October 9, 2020 17:30
Comment on lines 382 to 384
allPropsMixins = declaration.props.either.nodeHelper.mixins
?.map<Identifier>((mixin) => mixin.name)
?.toList(),
Copy link
Contributor

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?

Copy link
Contributor Author

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!

buffer
..writeln()
..writeln(' @override')
..writeln(' $classType get $fieldName => ${isConst ? 'const' : ''} $classType({');
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this in ea0e4aa!

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a 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!

example/builder/src/new_class_consumed_props.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
@@ -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.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@@ -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');
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:noice: Updated in 88e20b7!

@joebingham-wk joebingham-wk force-pushed the CPLAT-12194-functional-consumed-props branch from 728f513 to 7f801fa Compare October 15, 2020 01:42
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
///
/// This is useful in conjunction with [UiProps]'s `addUnconsumedProps`,
/// which expects [PropsMeta] to be provided in a [List].
List<PropsMeta> inList() => [this];
Copy link
Contributor Author

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', () {
Copy link
Contributor Author

@joebingham-wk joebingham-wk Oct 15, 2020

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) {
Copy link
Contributor Author

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.

@joebingham-wk joebingham-wk marked this pull request as ready for review October 15, 2020 20:57
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a 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!

lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
lib/src/util/map_util.dart Outdated Show resolved Hide resolved
lib/src/util/map_util.dart Outdated Show resolved Hide resolved
lib/src/util/map_util.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a 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

lib/src/component_declaration/builder_helpers.dart Outdated Show resolved Hide resolved
lib/src/util/react_util.dart Outdated Show resolved Hide resolved
lib/src/component/strictmode_component.dart Outdated Show resolved Hide resolved
lib/src/util/react_util.dart Show resolved Hide resolved
@greglittlefield-wf
Copy link
Contributor

QA +1

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a 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 !!!

@joebingham-wk
Copy link
Contributor Author

@Workiva/release-management-p

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from RM

@rmconsole7-wk rmconsole7-wk merged commit d094d02 into master Oct 26, 2020
@rmconsole7-wk rmconsole7-wk deleted the CPLAT-12194-functional-consumed-props branch October 26, 2020 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants