diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..ca1799631 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,73 @@ +# Contributing + +> We are working on a more thorough version of these contributing guidlines. For +> the time being, we've documented our temporary dual-release setup that is +> necessary for supporting Dart 1 and Dart 2 concurrently. + +## Dart 1 & Dart 2 Dual-Releases + +Long story short, we are unable to maintain a single codebase of over_react that +is compatible with both Dart 1 and Dart 2. Transformers only work on Dart 1 and +builders only work on Dart 2, and we can't maintain the transformer and builder +together due to dependency conflicts. + +> For more information on our Dart 2 migration, [see this guide](/doc/dart2_migration.md). + +Fortunately, this problem can be shouldered entirely by the maintainers via a +dual-release strategy (credit to the [dart2_constant](https://pub.dartlang.org/packages/dart2_constant) +for the idea). The result is that consumers will depend on a version range of +this library like they normally do and everything will _just work_. + +For every _version_ we want to release, we will actually release two releases - +a Dart 1 (transformer) version and a Dart 2 (builder) version. These two +releases will have the same semantic version, but will have unique build +suffixes. The `pub` client will then decide which one to install based on their +`environment.sdk` constraints and the active Dart SDK version. + +### Branches + +- `master` + - Dart2-only + - Provides a builder + - Environment constraint: `>=2.1.0 <3.0.0` + +- `master_dart1` + - Dart1-only + - Provides a transformer + - Environment constraint: `>=1.24.3 <2.0.0` + +### Release Process + +> Note that these steps are intended to be followed by Workiva employees, and as +> such have some references to internal tooling. + +For every release, do the following: + +1. Ensure the next release versions exist in MARV: + + Name | Branch + ---- | ------ + over_react 2.x.x-dart1 | master_dart1 + over_react 2.x.x | master + +1. Trigger the `over_react 2.x.x-dart1` release first and review the PR: + + - Ensure the updated `pubspec.yaml` version is correct, including the + `-dart1` suffix. + + - Ensure the build passes. + +1. Trigger the `over_react 2.x.x` release second and review the PR: + + - Ensure the updated `pubspec.yaml` version is correct. + + - Ensure the build passes. + + - **Add any necessary changelog updates to the Dart 2 version.** + +1. **Merge the Dart 1 release first and publish it to pub.** + +1. Merge the Dart 2 release second and publish it to pub. + +1. Re-recreate the Dart 1 release in MARV (it does not get recreated + automatically like the default release does). diff --git a/README.md b/README.md index 51f3e0afc..74d8805d3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![Build Status](https://travis-ci.org/Workiva/over_react.svg?branch=master)](https://travis-ci.org/Workiva/over_react) [![Test Coverage](https://codecov.io/github/Workiva/over_react/coverage.svg?branch=master)](https://codecov.io/github/Workiva/over_react?branch=master) -[![Strong Mode Compliant](https://img.shields.io/badge/strong_mode-on-brightgreen.svg)](https://github.com/Workiva/over_react/blob/master/analysis_options.yaml#L5) > A library for building statically-typed React UI components using Dart. @@ -15,7 +14,7 @@ > **Dart 2 Migration Guide** > > If you have existing over_react code written on Dart 1 and want to upgrade to -> Dart 2, please read the [**Dart 2 Migration Guide**](/doc/dart2_migration.md) +> Dart 2, please read the [**Dart 2 Migration Guide**](https://github.com/Workiva/over_react/blob/master/doc/dart2_migration.md) --- @@ -51,22 +50,10 @@ ```yaml dependencies: - over_react: ^1.29.0 + over_react: ^2.0.0 ``` -2. Add the `over_react` [transformer] to your `pubspec.yaml`. - - ```yaml - transformers: - - over_react - # Reminder: dart2js should come after any other transformers that touch Dart code - - $dart2js - ``` - - _Our transformer uses code generation to wire up the different pieces of your - component declarations - and to create typed getters/setters for `props` and `state`._ - -3. Include the native JavaScript `react` and `react_dom` libraries in your app’s `index.html` file, +2. Include the native JavaScript `react` and `react_dom` libraries in your app’s `index.html` file, and add an HTML element with a unique identifier where you’ll mount your OverReact UI component(s). ```html @@ -81,8 +68,8 @@ and add an HTML element with a unique identifier where you’ll mount your OverR - - + + ``` @@ -111,33 +98,33 @@ mount / render it into the HTML element you created in step 3. } ``` -5. Run `pub serve` in the root of your Dart project. +5. Run `pub run build_runner serve` in the root of your Dart project.   ### Running tests in your project -When running tests on code that uses our [transformer] _(or any code that imports `over_react`)_, -__you must run your tests using Pub__. +When running tests on code that uses our [builder] _(or any code that imports `over_react`)_, +__you must run your tests using build_runner__. +>**Warning:** Do **_not_** run tests via `pub run build_runner test` in a package while another instance of `build_runner` +(e.g. `pub run build_runner serve`)is running in that same package. [This workflow is unsupported by build_runner](https://github.com/dart-lang/build/issues/352#issuecomment-461554316) -1. Add the `test/pub_serve` transformer to your `pubspec.yaml` _after_ the `over_react` transformer. +1. Run tests through build_runner, and specify the platform to be a browser platform. Example: - ```yaml - transformers: - - over_react - - test/pub_serve: - $include: test/**_test{.*,}.dart - - $dart2js + ```bash + $ pub run build_runner test -- -p chrome test/your_test_file.dart ``` - -2. Use [the `--pub-serve` option](https://github.com/dart-lang/test#testing-with-barback) when running your tests: - + +1. When running tests in `over_react`, our `dart_test.yaml` specifies some handy presets for running tests in DDC and dart2js: + > **Note:** These presets exist only in `over_react`. + * To run tests in `over_react` compiled via DDC, run: ```bash - $ pub run test --pub-serve=8081 test/your_test_file.dart + $ pub run build_runner -- -P dartdevc + ``` + * To run tests in `over_react` compiled via dart2js, run: + ```bash + $ pub run build_runner -r -- -P dart2js ``` - - > __Note:__ `8081` is the default port used, but your project may use something different. Be sure to take note - of the output when running `pub serve` to ensure you are using the correct port.     @@ -155,8 +142,8 @@ The `over_react` library functions as an additional "layer" atop the [Dart react which handles the underlying JS interop that wraps around [React JS][react-js]. The library strives to maintain a 1:1 relationship with the React JS component class and API. -To do that, an OverReact component is comprised of four core pieces that are each wired up to our -Pub transformer using an analogous [annotation]. +To do that, an OverReact component is comprised of four core pieces that are each wired up +via our builder using an analogous [annotation]. 1. [UiFactory](#uifactory) 2. [UiProps](#uiprops) @@ -172,7 +159,7 @@ __`UiFactory` is a function__ that returns a new instance of a ```dart @Factory() -UiFactory Foo; +UiFactory Foo = _$Foo; ``` * This factory is __the entry-point__ to consuming every OverReact component. @@ -188,10 +175,14 @@ It can also be invoked as a function, serving as a builder for its analogous com ```dart @Props() -class FooProps extends UiProps { +class _$FooProps extends UiProps { // ... } ``` +* Note: The [builder] will make the concrete getters and setters available in a generated class which has the same name +as the class annotated with `@Props()`, but without the `_$` prefix (which would be `FooProps` in the above code). +The generated class will also have the same API. So, consumers who wish to extend the functionality of `_$FooProps` should +extend the generated version, `FooProps`.   @@ -199,10 +190,10 @@ class FooProps extends UiProps { ```dart @Factory() -UiFactory Foo; +UiFactory Foo = _$Foo; @Props() -class FooProps extends UiProps { +class _$FooProps extends UiProps { String color; } @@ -237,10 +228,10 @@ void baz() { ```dart @Factory() -UiFactory Foo; +UiFactory Foo = _$Foo; @Props() -class FooProps extends UiProps { +class _$FooProps extends UiProps { String color; } @@ -283,12 +274,16 @@ for each React component state property. ```dart @State() -class FooState extends UiState { +class _$FooState extends UiState { // ... } ``` > UiState is optional, and won’t be used for every component. +* Note: The [builder] will make the concrete getters and setters available in a generated class which has the same name +as the class annotated with `@State()`, but without the `_$` prefix (which would be `FooState` in the above code). +The generated class will also have the same API. So, consumers who wish to extend the functionality of `_$FooState` should +use the generated version, `FooState`.   @@ -664,7 +659,8 @@ Now that we’ve gone over how to [use the `over_react` package in your project] the [anatomy of a component](#anatomy-of-an-overreact-component) and the [DOM components](#dom-components-and-props) that you get for free from OverReact, you're ready to start building your own custom React UI components. -1. Start with one of the [component boilerplate templates](#component-boilerplate-templates) below. +1. Start with one of the [component boilerplate templates](#component-boilerplate-templates) below +(Or, use OverReact's [code snippets for Intellij and Vs Code](https://github.com/Workiva/over_react/blob/master/snippets/README.md)). * [Component](#component-boilerplate) _(props only)_ * [Stateful Component](#stateful-component-boilerplate) _(props + state)_ * [Flux Component](#flux-component-boilerplate) _(props + store + actions)_ @@ -674,10 +670,10 @@ that you get for free from OverReact, you're ready to start building your own cu 4. Run [the app you’ve set up to consume `over_react`](#using-it-in-your-project) ```bash - $ pub serve + $ pub run build_runner serve ``` - _That’s it! Code will be automatically generated on the fly by Pub!_ + _That’s it! Code will be automatically generated on the fly by the builder!_ > __Check out some custom [component demos] to get a feel for what’s possible!__ @@ -686,7 +682,7 @@ that you get for free from OverReact, you're ready to start building your own cu ### Component Boilerplate Templates -* #### [Dart 1 and Dart 2 Backwards Compatible VS Code and WebStorm/IntelliJ Snippets](snippets/README.md) +* #### [Dart 1 and Dart 2 Backwards Compatible VS Code and WebStorm/IntelliJ Snippets](https://github.com/Workiva/over_react/blob/master/snippets/README.md) * #### Component Boilerplate @@ -694,10 +690,10 @@ that you get for free from OverReact, you're ready to start building your own cu import 'package:over_react/over_react.dart'; @Factory() - UiFactory Foo; + UiFactory Foo = _$Foo; @Props() - class FooProps extends UiProps { + class _$FooProps extends UiProps { // Props go here, declared as fields: bool isDisabled; Iterable items; @@ -727,17 +723,17 @@ that you get for free from OverReact, you're ready to start building your own cu import 'package:over_react/over_react.dart'; @Factory() - UiFactory Bar; + UiFactory Bar = _$Bar; @Props() - class BarProps extends UiProps { + class _$BarProps extends UiProps { // Props go here, declared as fields: bool isDisabled; Iterable items; } @State() - class BarState extends UiState { + class _$BarState extends UiState { // State goes here, declared as fields: bool isShown; } @@ -772,10 +768,10 @@ that you get for free from OverReact, you're ready to start building your own cu import 'package:over_react/over_react.dart'; @Factory() - UiFactory Baz; + UiFactory Baz = _$Baz; @Props() - class BazProps extends FluxUiProps { + class _$BazProps extends FluxUiProps { // Props go here, declared as fields. // `actions` and `store` are already defined for you! } @@ -802,16 +798,16 @@ that you get for free from OverReact, you're ready to start building your own cu import 'package:over_react/over_react.dart'; @Factory() - UiFactory Baz; + UiFactory Baz = _$Baz; @Props() - class BazProps extends FluxUiProps { + class _$BazProps extends FluxUiProps { // Props go here, declared as fields. // `actions` and `store` are already defined for you! } @State() - class BazState extends UiState { + class _$BazState extends UiState { // State goes here, declared as fields. } @@ -855,14 +851,14 @@ another component. /// /// See: . @Factory() - UiFactory DropdownButton; + UiFactory DropdownButton = _$DropdownButton; ``` _Bad:_ ```dart /// Component Factory for a dropdown button component. @Factory() - UiFactory DropdownButton; + UiFactory DropdownButton = _$DropdownButton; ```   @@ -877,7 +873,7 @@ and document that value in a comment. _Good:_ ```dart @Props() - DropdownButtonProps extends UiProps { + _$DropdownButtonProps extends UiProps { /// Whether the [DropdownButton] appears disabled. /// /// Default: `false` @@ -893,7 +889,7 @@ and document that value in a comment. } @State() - DropdownButtonState extends UiState { + _$DropdownButtonState extends UiState { /// Whether the [DropdownButton]'s child [DropdownMenu] is open. /// /// Initial: [DropdownButtonProps.initiallyOpen] @@ -919,13 +915,13 @@ and document that value in a comment. _Bad:_ ```dart @Props() - DropdownButtonProps extends UiProps { + _$DropdownButtonProps extends UiProps { bool isDisabled; bool initiallyOpen; } @State() - DropdownButtonState extends UiState { + _$DropdownButtonState extends UiState { bool isOpen; } @@ -945,7 +941,7 @@ an informative comment. _Good:_ ```dart @Props() - DropdownButtonProps extends UiProps { + _$DropdownButtonProps extends UiProps { /// Whether the [DropdownButton] appears disabled. /// /// Default: `false` @@ -961,7 +957,7 @@ an informative comment. } @State() - DropdownButtonState extends UiState { + _$DropdownButtonState extends UiState { /// Whether the [DropdownButton]'s child [DropdownMenu] is open. /// /// Initial: [DropdownButtonProps.initiallyOpen] @@ -972,56 +968,19 @@ an informative comment. _Bad:_ ```dart @Props() - DropdownButtonProps extends UiProps { + _$DropdownButtonProps extends UiProps { bool isDisabled; bool initiallyOpen; } @State() - DropdownButtonState extends UiState { + _$DropdownButtonState extends UiState { bool isOpen; } ```   -### Common Pitfalls - -Below you’ll find some common errors / issues that new consumers run into when building custom components. - -> Don’t see the issue you're having? [Tell us about it.][new-issue] - ---- - -#### `null object does not have a method 'call'` - -``` -ⓧ Exception: The null object does not have a method 'call'. -``` - -This error is thrown when you call a `@Factory()` function that has not been initialized due to -the `over_react` [transformer] not running, you’ll get this error. - -__Make sure you’ve followed the [setup instructions](#using-it-in-your-project).__ - ---- - -### 404 on `.dart` file - -``` -ⓧ GET http://localhost:8080/src/your_component.dart -ⓧ An error occurred loading file: http://localhost:8080/src/your_component.dart -``` - -When the `over_react` [transformer] finds something wrong with your file, it logs an error in Pub and causes the -invalid file to 404. This ensures that when the transformer breaks, `pub build` will break, and you’ll know about it. - -__Check your `pub serve` output for errors.__ - -  -  - - ## Contributing @@ -1046,7 +1005,7 @@ The `over_react` library adheres to [Semantic Versioning](http://semver.org/): [component demos]: https://workiva.github.io/over_react/demos [contributing-docs]: https://github.com/Workiva/over_react/blob/master/.github/CONTRIBUTING.md -[transformer]: https://github.com/Workiva/over_react/blob/master/lib/src/transformer/README.md +[builder]: https://github.com/Workiva/over_react/blob/master/lib/src/builder/README.md [annotations]: https://github.com/Workiva/over_react/blob/master/lib/src/component_declaration/annotations.dart [annotation]: https://github.com/Workiva/over_react/blob/master/lib/src/component_declaration/annotations.dart [component_base.dart]: https://github.com/Workiva/over_react/blob/master/lib/src/component_declaration/component_base.dart diff --git a/build.yaml b/build.yaml index 672eaf285..8e4a2fe97 100644 --- a/build.yaml +++ b/build.yaml @@ -13,7 +13,7 @@ targets: generate_for: exclude: # This tests un-built behavior, and therefore should not be built - - "test/over_react/component_declaration/transformer_helpers_test.dart" + - "test/over_react/component_declaration/builder_helpers_test.dart" # builder uses mirrors and will cause a build to fail when using build web compilers # vm tests require the use of mirrors diff --git a/docs.yml b/docs.yml index 32065a527..92ed7a8ff 100644 --- a/docs.yml +++ b/docs.yml @@ -2,5 +2,12 @@ title: over_react base: github:Workiva/over_react/ src: README.md topics: - - title: Transformer - src: lib/src/transformer/README.md + - title: Builder + src: lib/src/builder/README.md + + - title: OverReact Dart 2 Migration Guide + src: doc/dart2_migration.md + + - title: OverReact Dart 2 Code Snippets + src: snippets/README.md + diff --git a/lib/over_react.dart b/lib/over_react.dart index 162669513..c348e1133 100644 --- a/lib/over_react.dart +++ b/lib/over_react.dart @@ -40,7 +40,7 @@ export 'src/component/prop_typedefs.dart'; export 'src/component/resize_sensor.dart'; export 'src/component_declaration/flux_component.dart'; export 'src/component_declaration/built_redux_component.dart'; -export 'src/component_declaration/transformer_helpers.dart'; +export 'src/component_declaration/builder_helpers.dart'; export 'src/util/character_constants.dart'; export 'src/util/class_names.dart'; export 'src/util/constants_base.dart'; diff --git a/lib/src/builder/README.md b/lib/src/builder/README.md new file mode 100644 index 000000000..8b1504540 --- /dev/null +++ b/lib/src/builder/README.md @@ -0,0 +1,213 @@ +# OverReact Builder + +[](#__START_EMBEDDED_README__) + +OverReact components are declared using a set of [annotations] which are +picked up by the `over_react` builder. + +This builder generates code, wiring up the different pieces of component +declarations and creating typed getters/setters for props and state. + +This allows boilerplate to be significantly reduced, making the code you write +much cleaner and more _grokkable_. + +> Check out some [component demos] to see the builder in action. + +  +  + +## Wiring it all up + +__Be sure to familiarize yourself with the [OverReact library] first.__ + +The builder wires up your factory, props class, and component class so that you don't have to! + + +### The generation process + +> All of this generation happens "under the hood", but you can see it in action for your +own components by viewing the generated .over_react.g.dart file. + +1. A component is declared. + + ```dart + @Factory() + UiFactory Foo = _$Foo; + + @Props() + class _$FooProps extends UiProps { + // ... + } + + @Component() + class FooComponent extends UiComponent { + @override + render() { + // ... + } + } + ``` + + Note that we've annotated our component pieces with `@Factory()`, `@Props()`, and `@Component()`. + These are what the builder uses as "hooks" to find your component. + + Okay, so we've defined our component. Let's look at what the builder does. + +2. The builder creates the consumable implementation of the props class. This is the class which contains concrete +getters/setters (via the `_$FooPropsAccessorsMixin` class) + ```dart + class FooProps extends _$FooProps with _$FooPropsAccessorsMixin { + static const PropsMeta meta = _$metaForFooProps; + } + ``` + +3. The builder creates a concrete props implementation class + ``` + + ```dart + // Concrete props implementation. + // + // Implements constructor and backing map, and links up to generated component factory. + class _$$FooProps extends _$FooProps with _$FooPropsAccessorsMixin implements FooProps { + _$$FooProps(Map backingMap) : this._props = backingMap ?? {}; + + /// The backing props map proxied by this class. + @override + Map get props => _props; + final Map _props; + + /// Let [UiProps] internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + /// The [ReactComponentFactory] associated with the component built by this class. + @override + ReactComponentFactoryProxy get componentFactory => $FooComponentFactory; + + /// The default namespace for the prop getters/setters generated for this class. + @override + String get propKeyNamespace => 'FooProps.'; + } + ``` + + It does this since the class we defined in our code inherits pseudo-abstract stubbed + members and doesn't have the constructor we need. + +3. A fully implemented component class which extends our component class. + + ```dart + // Concrete component implementation. + // + // Implements typed props/state factories, defaults `consumedPropKeys` to the keys + // generated for the associated props class. + class _$FooComponent extends FooComponent { + @override + typedPropsFactory(Map backingMap) => new _$$FooProps(backingMap); + + /// Let [UiComponent] internals know that this class has been generated. + @override + bool get $isClassGenerated => true; + + /// The default consumed props, taken from _$FooProps. + /// Used in [UiProps.consumedProps] if [consumedProps] is not overridden. + @override + final List $defaultConsumedProps = const [_$metaForFooProps]; + } + ``` + + Note that the `typedPropsFactory` variable is wired up to use the props implementation + class's constructor. This lets us get an instance of that class when we use the `props` + getter and the `newProps()` method, and is necessary since the code we wrote + doesn't have a proper constructor. + +4. Our fully implemented component class is registered with the [react-dart] wrapper. + + ```dart + // React component factory implementation. + // + // Registers component implementation and links type meta to builder factory. + final $FooComponentFactory = registerComponent(() => new _$FooComponent(), + builderFactory: Foo, + componentClass: FooComponent, + isWrapper: false, + parentType: null, + displayName: 'Foo'); + + ``` + +5. Finally, the initializer for our factory (_$Foo) is generated with a function that returns a new instance of our +private props implementation. This factory is __the entry-point__ to externally consuming our +component and props class. + + ```dart + _$$FooProps _$Foo([Map backingProps]) => new _$$FooProps(backingProps); + ``` + +  +  + + + +## Props / State Getters and Setters + +Writing a statically-typed prop / state API for React components in Dart proved to be a huge pain when we +attempted to do it from scratch. + +We found that the most straightforward way to adhere to React patterns was to use `Map`s for `props` and `state`. + +So we went about defining typed getters and setters on `MapView`-like classes which proxy Map key-value pairs. +However, typing these getters and setters quickly became tedious +_(especially if you need namespaced keys for platform scalability)_: + +```dart +class FooProps extends UiProps { + String get title => props['FooProps.title']; + set title(String value) => props['FooProps.title'] = value; + + bool get isEnabled => props['FooProps.isEnabled']; + set isEnabled(bool value) => props['FooProps.isEnabled'] = value; + + MouseEventCallback get onClick => props['FooProps.onClick']; + set onClick(Callback value) => props['FooProps.onClick'] = value; + + // Imagine a component with 20 of these... yuck. +} +``` + +With the builder, we cut down on repetition while preserving statically-typed getter and setters. + +Props and state are declared using _fields_, making the actual code you write much simpler - +and much more like the React JS library intended: + +```dart +@Props() +class _$FooProps extends UiProps { + String title; + + bool isEnabled; + + MouseEventCallback onClick; + + // ... +} + +@State() +class _$FooState extends UiState { + bool isShown; + + String currentText; + + // ... +} +``` + +> Check out some [component demos] for more info about using fields to define props and state values in the real world. + +  +  + + +[OverReact library]: https://github.com/Workiva/over_react/blob/master/README.md +[annotations]: https://github.com/Workiva/over_react/blob/master/lib/src/component_declaration/annotations.dart +[component demos]: https://workiva.github.io/over_react/demos/ +[react-dart]: https://github.com/cleandart/react-dart diff --git a/lib/src/component/dom_components.dart b/lib/src/component/dom_components.dart index 63eb5a296..a7370604c 100644 --- a/lib/src/component/dom_components.dart +++ b/lib/src/component/dom_components.dart @@ -17,7 +17,7 @@ library over_react.dom_components; import 'package:over_react/src/component/prop_mixins.dart'; import 'package:over_react/src/component_declaration/component_base.dart' as component_base; -import 'package:over_react/src/component_declaration/transformer_helpers.dart' as transformer_helpers; +import 'package:over_react/src/component_declaration/builder_helpers.dart' as builder_helpers; import 'package:react/react.dart' as react; import 'package:react/react_client.dart'; @@ -36,14 +36,14 @@ DomProps domProps([Map backingMap]) => new DomProps(null, backingMap); typedef DomProps DomPropsFactory(); -// Include pieces from transformer_helpers so that consumers can type these instances +// Include pieces from builder_helpers so that consumers can type these instances // as the `UiProps` exposed in `over_react.dart` and not have to pull in `component_base`. class DomProps extends component_base.UiProps with DomPropsMixin, - transformer_helpers.GeneratedClass + builder_helpers.GeneratedClass implements - transformer_helpers.UiProps { + builder_helpers.UiProps { // Wrap Map literal in parens to work around https://github.com/dart-lang/sdk/issues/24410 DomProps(this.componentFactory, [Map props]) : this.props = props ?? ({}); @@ -57,13 +57,13 @@ class DomProps extends component_base.UiProps String get propKeyNamespace => ''; } -// Include pieces from transformer_helpers so that consumers can type these instances +// Include pieces from builder_helpers so that consumers can type these instances // as the `UiProps` exposed in `over_react.dart` and not have to pull in `component_base`. class SvgProps extends component_base.UiProps with DomPropsMixin, SvgPropsMixin, - transformer_helpers.GeneratedClass + builder_helpers.GeneratedClass implements DomProps { // Wrap Map literal in parens to work around https://github.com/dart-lang/sdk/issues/24410 diff --git a/lib/src/component_declaration/annotations.dart b/lib/src/component_declaration/annotations.dart index 10d36e3c2..be11af73d 100644 --- a/lib/src/component_declaration/annotations.dart +++ b/lib/src/component_declaration/annotations.dart @@ -15,7 +15,7 @@ // Dummy annotations that would be used by Pub code generator library over_react.component_declaration.annotations; -/// Annotation used with the `over_react` transformer to declare a [UiFactory] for a component. +/// Annotation used with the `over_react` builder to declare a [UiFactory] for a component. /// /// @Factory() /// UiFactory Foo = _$Foo; @@ -25,7 +25,7 @@ class Factory { const Factory(); } -/// Annotation used with the `over_react` transformer to declare a [UiProps] class for a component. +/// Annotation used with the `over_react` builder to declare a [UiProps] class for a component. /// /// Props are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -43,7 +43,7 @@ class Props implements TypedMap { const Props({this.keyNamespace}); } -/// Annotation used with the `over_react` transformer to declare a [UiState] class for a component. +/// Annotation used with the `over_react` builder to declare a [UiState] class for a component. /// /// State properties are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -61,7 +61,7 @@ class State implements TypedMap { const State({this.keyNamespace}); } -/// Annotation used with the `over_react` transformer to declare a [UiComponent] class for a component. +/// Annotation used with the `over_react` builder to declare a [UiComponent] class for a component. /// /// @Component() /// class FooComponent extends UiComponent { @@ -104,7 +104,7 @@ class Component { }); } -/// Annotation used with the `over_react` transformer to declare an abstract [UiProps] class for an abstract component. +/// Annotation used with the `over_react` builder to declare an abstract [UiProps] class for an abstract component. /// /// Props are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -120,7 +120,7 @@ class AbstractProps implements TypedMap { const AbstractProps({this.keyNamespace}); } -/// Annotation used with the `over_react` transformer to declare an abstract [UiProps] class for an abstract component. +/// Annotation used with the `over_react` builder to declare an abstract [UiProps] class for an abstract component. /// /// State properties are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -136,7 +136,7 @@ class AbstractState implements TypedMap { const AbstractState({this.keyNamespace}); } -/// Annotation used with the `over_react` transformer to declare an abstract [UiComponent] class for an abstract component. +/// Annotation used with the `over_react` builder to declare an abstract [UiComponent] class for an abstract component. /// /// @AbstractComponent() /// abstract class QuxComponent extends UiComponent {} @@ -144,7 +144,7 @@ class AbstractComponent { const AbstractComponent(); } -/// Annotation used with the `over_react` transformer to declare a mixin for use in a [UiProps] class. +/// Annotation used with the `over_react` builder to declare a mixin for use in a [UiProps] class. /// /// Props are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -164,7 +164,7 @@ class PropsMixin implements TypedMap { const PropsMixin({this.keyNamespace}); } -/// Annotation used with the `over_react` transformer to declare a mixin for use in a [UiState] class. +/// Annotation used with the `over_react` builder to declare a mixin for use in a [UiState] class. /// /// State properties are declared as fields, which act as stubs for generated getters/setters that proxy Map key-value pairs. /// @@ -208,7 +208,7 @@ const Accessor requiredProp = const Accessor(isRequired: true); /// } const Accessor nullableRequiredProp = const Accessor(isRequired: true, isNullable: true); -/// Annotation used with the `over_react` transformer to customize individual accessors (props/state fields). +/// Annotation used with the `over_react` builder to customize individual accessors (props/state fields). /// /// Validation occurs in `UiComponent.validateRequiredProps` which requires super calls into `componentWillMount` and /// `componentWillReceiveProps`. diff --git a/lib/src/component_declaration/transformer_helpers.dart b/lib/src/component_declaration/builder_helpers.dart similarity index 92% rename from lib/src/component_declaration/transformer_helpers.dart rename to lib/src/component_declaration/builder_helpers.dart index 998d80cfb..e7fe468ce 100644 --- a/lib/src/component_declaration/transformer_helpers.dart +++ b/lib/src/component_declaration/builder_helpers.dart @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -library over_react.component_declaration.transformer_helpers; +library over_react.component_declaration.builder_helpers; import 'package:react/react_client.dart'; @@ -47,7 +47,7 @@ class GeneratedClass { /// See: [component_base.UiComponent] /// -/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. +/// Use with the over_react builder via the `@Component()` ([annotations.Component]) annotation. abstract class UiComponent extends component_base.UiComponent with GeneratedClass { /// This class should not be instantiated directly, and throws an error to indicate this. UiComponent() { @@ -75,7 +75,7 @@ abstract class UiComponent extends component_base.UiComp /// See: [component_base.UiStatefulComponent] /// -/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. +/// Use with the over_react builder via the `@Component()` ([annotations.Component]) annotation. abstract class UiStatefulComponent extends component_base.UiStatefulComponent with GeneratedClass { /// This class should not be instantiated directly, and throws an error to indicate this. @@ -119,7 +119,7 @@ abstract class UiStatefulComponent "UngeneratedError: $message.\n\n" - "Ensure that the `over_react` transformer is included in your pubspec.yaml, " - "and that this code is being run using Pub."; + "Ensure that you're running a build via build_runner."; } /// Thrown when a class is directly instantiated when it should not be. diff --git a/lib/src/component_declaration/built_redux_component.dart b/lib/src/component_declaration/built_redux_component.dart index 7d6abccb9..92f0ee7d5 100644 --- a/lib/src/component_declaration/built_redux_component.dart +++ b/lib/src/component_declaration/built_redux_component.dart @@ -23,7 +23,7 @@ import 'package:over_react/over_react.dart'; /// Builds on top of [UiProps], adding typed props for [Store] in order to integrate with `built_redux`. /// -/// Use with the over_react transformer via the `@Props()` ([annotations.Props]) annotation. +/// Use with the over_react builder via the `@Props()` ([annotations.Props]) annotation. /// /// __Warning:__ This will be deprecated in an upcoming release in favor of a different approach to /// creating a `built_redux` component. @@ -45,7 +45,7 @@ abstract class BuiltReduxUiProps, B extends Builder, /// user interactions and events into [Action]s. /// * Redux components can use data from one [Store] instance to define the resulting component. /// -/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. +/// Use with the over_react builder via the `@Component()` ([annotations.Component]) annotation. /// /// __Note:__ [Substate] must be a comparable object to avoid unnecessary redraws, /// it is reccomended that [Substate] either be a primitive, built_value, build_collection or an Object diff --git a/lib/src/component_declaration/flux_component.dart b/lib/src/component_declaration/flux_component.dart index ef6f97cea..da8dbf24b 100644 --- a/lib/src/component_declaration/flux_component.dart +++ b/lib/src/component_declaration/flux_component.dart @@ -20,11 +20,11 @@ import 'package:meta/meta.dart'; import 'package:w_flux/w_flux.dart'; import './annotations.dart' as annotations; -import './transformer_helpers.dart'; +import './builder_helpers.dart'; /// Builds on top of [UiProps], adding typed props for [Action]s and [Store]s in order to integrate with w_flux. /// -/// Use with the over_react transformer via the `@Props()` ([annotations.Props]) annotation. +/// Use with the over_react builder via the `@Props()` ([annotations.Props]) annotation. abstract class FluxUiProps extends UiProps { String get _actionsPropKey => '${propKeyNamespace}actions'; String get _storePropKey => '${propKeyNamespace}store'; @@ -65,7 +65,7 @@ abstract class FluxUiProps extends UiProps { /// * Flux components can use data from one or many [Store] instances to define /// the resulting component. /// -/// Use with the over_react transformer via the `@Component()` ([annotations.Component]) annotation. +/// Use with the over_react builder via the `@Component()` ([annotations.Component]) annotation. /// /// > Related: [FluxUiStatefulComponent] abstract class FluxUiComponent extends UiComponent @@ -105,7 +105,7 @@ abstract class FluxUiComponent extends UiComponent Related: [FluxUiComponent] abstract class FluxUiStatefulComponent diff --git a/test/over_react/component_declaration/transformer_helpers_test.dart b/test/over_react/component_declaration/builder_helpers_test.dart similarity index 98% rename from test/over_react/component_declaration/transformer_helpers_test.dart rename to test/over_react/component_declaration/builder_helpers_test.dart index 9b81a426d..40e6d94c4 100644 --- a/test/over_react/component_declaration/transformer_helpers_test.dart +++ b/test/over_react/component_declaration/builder_helpers_test.dart @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -library over_react.transformer_generation.helpers_test; +library over_react.builder_generation.helpers_test; -import 'package:over_react/src/component_declaration/transformer_helpers.dart'; +import 'package:over_react/src/component_declaration/builder_helpers.dart'; import 'package:test/test.dart'; final Matcher throwsUngeneratedError = throwsA(const TypeMatcher()); diff --git a/test/over_react_component_declaration_test.dart b/test/over_react_component_declaration_test.dart index 958f482f9..d557db6a6 100644 --- a/test/over_react_component_declaration_test.dart +++ b/test/over_react_component_declaration_test.dart @@ -27,7 +27,8 @@ import 'over_react/component_declaration/component_base_test.dart' as component_ import 'over_react/component_declaration/component_type_checking_test.dart' as component_type_checking_test; import 'over_react/component_declaration/flux_component_test.dart' as flux_component_test; import 'over_react/component_declaration/redux_component_test.dart' as redux_component_test; -import 'over_react/component_declaration/transformer_helpers_test.dart' as transformer_helpers_test; + +import 'over_react/component_declaration/builder_helpers_test.dart' as builder_helpers_test; import 'over_react/component_declaration/builder_integration_tests/abstract_accessor_integration_test.dart' as abstract_accessor_integration_test; import 'over_react/component_declaration/builder_integration_tests/accessor_mixin_integration_test.dart' as accessor_mixin_integration_test; import 'over_react/component_declaration/builder_integration_tests/component_integration_test.dart' as component_integration_test; @@ -55,7 +56,7 @@ main() { flux_component_test.main(); redux_component_test.main(); - transformer_helpers_test.main(); + builder_helpers_test.main(); abstract_accessor_integration_test.main(); accessor_mixin_integration_test.main();