Workiva / react-dart

Dart Bindings for React JS
BSD 2-Clause "Simplified" License
413 stars 67 forks source link

CPLAT-8122 Shorten propTypes boilerplate #228

Closed aaronlademann-wf closed 5 years ago

aaronlademann-wf commented 5 years ago

Motivation

The Component2.propTypes boilerplate was unnecessarily verbose.

Changes

  1. Add a class that contains the metadata that was previously provided as separate arguments, and change the PropValidator typedef signature to only require two arguments - with the second argument being an instance of the metadata class.

    Before:

    @override
    get propTypes => {
      'name': (Map props, propName, componentName, location, propFullName) {
        if (props[propName].length > 20) {
          return ArgumentError('...');
        }
        return null;
      },
    };

    After:

    @override
    get propTypes => {
      'name': (Map props, info) {
        if (props[info.propName].length > 20) {
          return ArgumentError('...');
        }
        return null;
      },
    };
  2. Update JS interop to pass through the field values from the ReactValidatorInfo fields as individual arguments to the JS React.propTypes function.

  3. Update some dynamic call sites where they could be tightened to at least Function.

Review

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

Please review: @greglittlefield-wf @joebingham-wk @kealjones-wk @sydneyjodon-wk

QA Checklist

kealjones-wk commented 5 years ago

+10