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

FED-1717 Finalize null-safe props/state implementation and utilities, add tests #869

Merged
merged 37 commits into from
Jan 5, 2024

Conversation

greglittlefield-wf
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf commented Dec 13, 2023

Motivation

The WIP branch had a mostly-complete implementation of null-safe props and state, but it needed to be finished up and tested.

We also needed to implement utilities for safely reading required non-nullable props from partial props objects.

Changes

  • Finalize generation of late props
    • The existing implementation was actually pretty complete, and just needed a bugfix for props that were both late and had an @Accessor annotation
  • Add utility extensions methods - ui_props_self_typed_extension.dart
    • getRequiredProp and getRequiredPropOrNull, for safely reading required non-nullable props when they might not be specified
    • getPropKey and containsProp, required for implementing getRequiredProp
    • Add basic example in example/builder/partial.dart
  • Generate $getPropKey (used by getPropKey, needed for utilities above) for all props classes
  • Add manual implementations of $getPropKey to non-generated classes, with a special case for UiPropsMapView (see breaking changes note)
  • Don't add documentation in main README and other places; that'll be handled in a follow-up ticket FED-1978
  • Add tests for
    • Props/state of various requiredness and nullabilities, for all boilerplate versions - null_safe_accessor_integration_test.dart in various folders under test/over_react/component_declaration/builder_integration_tests/
      • Reading/writing
      • Requiredness in PropsMeta
    • Builder warnings from mixing late and legacy required prop annotations
    • New extension methods, including cases reading required props - ui_props_self_typed_extension_test.dart
    • $getPropKey:
      • generated implementation for each boilerplate - under test/over_react/component_declaration/builder_integration_tests/
    • manual implementations for all non-generated UiProps classes in lib: UiPropsMapView, DomProps, SvgProps, GenericUiProps, ProviderProps, ConsumerProps

Breaking changes

  • UiPropsMapView (which has been deprecated for a while now) is now abstract and requires subclasses to override selfFactory, in order for it to be able to implement $getPropKey
    • Other props classes, including the new props map view boilerplate, generate this, and we can't implement this since we can't call the constructor of consumers' subclasses
  • ProviderProps.props widened from JsMap to Map - this seemed to be an oversight in the implementation, and this typing prevented it from implementing $getPropKey. I wouldn't expect this to impact consumers.

Release Notes

Review

See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.

Please review:

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 Frontend Frameworks Design 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a lot of generated file diffs in this PR with just the $getPropKey changes.

If you'd like to hide them when reviewing this PR to cut down on noise:

  1. Scroll down to the bottom of the /files page to trigger all files to load
  2. Run the following snippet in the console to hide files ending in .over_react.g.dart:
     document.querySelectorAll('[data-tagsearch-path$=".over_react.g.dart"]')
         .forEach((e) => e.hidden = true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these null_safe_accessor_integration_test.dart tests should be the same, except for the component boilerplate.

Comment on lines -35 to +36
component_base.UiProps {
UiProps {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implementing the generated UiProps makes it so that we can use @override in the methods we're overriding below; not sure why we weren't always doing this.

@greglittlefield-wf greglittlefield-wf marked this pull request as ready for review December 13, 2023 23:51
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.

Just a couple of questions.

Way to put a bow on this Greg!!!

lib/src/util/context.dart Show resolved Hide resolved
lib/src/util/context.dart Show resolved Hide resolved

test('the late keyword and the requiredProp annotation', () {
var body = '''@requiredProp
late var bar;''';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm imagining this trendy new club in old town... called the var bar

Copy link
Contributor

Choose a reason for hiding this comment

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

Its open late.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a pretty great name 😂

Its open late.

Lolol 😂

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

Can't Wait

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.

QA +1

  • Passing CI

@greglittlefield-wf greglittlefield-wf merged commit 31940a6 into v5_wip Jan 5, 2024
7 checks passed
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.

4 participants