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

RM-79371 Release over_react 3.8.0 #616

Merged
merged 112 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
e5f8e78
Allow displayName to be passed to forwardRef
aaronlademann-wf Jan 23, 2020
9c8825e
Improve / add forwardRef examples
aaronlademann-wf Jan 23, 2020
dd8bb52
Initial spike for other branch
sydneyjodon-wk Jul 7, 2020
a81cdf8
Add v5_functionComponent to parsing versions
sydneyjodon-wk Jul 7, 2020
8e2d970
Update generated file and error handling
sydneyjodon-wk Jul 7, 2020
d773544
Parse ComponentFactoryDeclarations
sydneyjodon-wk Jul 9, 2020
86bc327
Remove v5 and update PropsMapViewOrFunctionComponentDeclaration
sydneyjodon-wk Jul 9, 2020
6958e22
Update example
sydneyjodon-wk Jul 10, 2020
7dc77f6
Add codegen for FunctionComponentConfig
sydneyjodon-wk Jul 10, 2020
027cd66
Fix test failures and format
sydneyjodon-wk Jul 10, 2020
3e62161
Update getPropsNameFromConfig
sydneyjodon-wk Jul 10, 2020
e2da213
Add initial parsing tests
sydneyjodon-wk Jul 11, 2020
42005e2
Generate config for each factory to keep correct displayName
sydneyjodon-wk Jul 13, 2020
685e9d7
Add parsing for generic function components
sydneyjodon-wk Jul 14, 2020
659692e
Move defaultProps to react-dart
sydneyjodon-wk Jul 14, 2020
1d614a9
Update pubspec dependency override
sydneyjodon-wk Jul 14, 2020
f57ea6c
Add codegen tests
sydneyjodon-wk Jul 14, 2020
68db3d4
Handle parsing null config and custom props factory
sydneyjodon-wk Jul 16, 2020
d9d0708
Add function component snippets
sydneyjodon-wk Jul 16, 2020
d71da40
Format
sydneyjodon-wk Jul 16, 2020
4885e6b
Merge branch 'master' into CPLAT-3873-function-components
sydneyjodon-wk Jul 16, 2020
b19542c
Initial integration tests
sydneyjodon-wk Jul 17, 2020
49d1f5e
Merge branch 'master' into CPLAT-3873-function-components
sydneyjodon-wk Jul 17, 2020
27bc400
Revert "Initial integration tests"
sydneyjodon-wk Jul 17, 2020
3828257
Revert "Revert "Initial integration tests""
sydneyjodon-wk Jul 17, 2020
6fa267e
Remove unused import
sydneyjodon-wk Jul 17, 2020
0a4d434
Add tests based on component tests
sydneyjodon-wk Jul 17, 2020
9ef8829
Add test cases for custom PropsFactory
sydneyjodon-wk Jul 17, 2020
a2d31b2
Add tests for function components using UiProps
sydneyjodon-wk Jul 20, 2020
e43751a
Remove defaultProps and update examples
sydneyjodon-wk Jul 20, 2020
f99e40d
Cleanup tests
sydneyjodon-wk Jul 20, 2020
3a2daeb
Remove unused import
sydneyjodon-wk Jul 20, 2020
50c6b57
Resolve merge conflicts with master, update boilerplate in documentat…
smaifullerton-wk Jul 21, 2020
59e8d8e
Update function name and doc comments
sydneyjodon-wk Jul 22, 2020
b759f8a
Update migration guide examples
sydneyjodon-wk Jul 22, 2020
6ca4f3b
Consume react ^5.4.0
smaifullerton-wk Jul 22, 2020
cec79b9
Update based on reviewer feedback
sydneyjodon-wk Jul 23, 2020
cd8b296
Temporarily point to react 5.5.0-wip
aaronlademann-wf Jul 23, 2020
36eff3b
Merge 'upstream/function-components-wip' into improve-forwardref-docu…
aaronlademann-wf Jul 23, 2020
f117e9d
Merge 'upstream/function-components-wip' into CPLAT-3873-function-com…
aaronlademann-wf Jul 23, 2020
d1c01d7
Remove yield for non-generated factories
sydneyjodon-wk Jul 23, 2020
eaa69ca
Add factory grouping and update examples
sydneyjodon-wk Jul 24, 2020
0e38d4d
Add parsing for hocs and update wrapper function typing
sydneyjodon-wk Jul 24, 2020
82f92a4
Run build and add null check
sydneyjodon-wk Jul 24, 2020
4aa280b
Add the first few hooks
sydneyjodon-wk Jul 24, 2020
0fd444a
Update generic args for uiFunction
sydneyjodon-wk Jul 24, 2020
e7a263d
Update uiFunction args
sydneyjodon-wk Jul 24, 2020
4093fe2
Merge branch 'CPLAT-3873-function-components' into CPLAT-8665-react-h…
sydneyjodon-wk Jul 24, 2020
b934fb3
Expose the rest of the hooks
sydneyjodon-wk Jul 25, 2020
4283b47
Fix formatting
sydneyjodon-wk Jul 25, 2020
c30ae72
Fix failing tests
sydneyjodon-wk Jul 25, 2020
c22f0a2
Address feedback
sydneyjodon-wk Jul 27, 2020
62e05d8
Merge pull request #606 from Workiva/CPLAT-3873-function-components
greglittlefield-wf Jul 27, 2020
fa6ce35
Merge branch 'function-components-wip' into CPLAT-8665-react-hooks
sydneyjodon-wk Jul 28, 2020
6baec86
Add memo wrapper
smaifullerton-wk Jul 28, 2020
e800d4f
Separate hooks examples into different files
sydneyjodon-wk Jul 28, 2020
f65ebb1
Update doc comments
sydneyjodon-wk Jul 28, 2020
6994fd2
Fix useContext
sydneyjodon-wk Jul 28, 2020
a29da58
Merge branch 'function-components-wip' of github.com:Workiva/over_rea…
joebingham-wk Jul 29, 2020
53fd919
Initial implementation
joebingham-wk Jul 29, 2020
968de33
Add first go at examples
joebingham-wk Jul 29, 2020
2a940e3
CPLAT-9347 Add memo for function components
smaifullerton-wk Jul 29, 2020
b2bee79
Apply suggestions from code review
sydneyjodon-wk Jul 29, 2020
a168750
Fix import
sydneyjodon-wk Jul 29, 2020
5ca5761
Merge pull request #611 from Workiva/CPLAT-8665-react-hooks
greglittlefield-wf Jul 29, 2020
04b7b2c
Update built files
smaifullerton-wk Jul 29, 2020
2837579
Revert formatting on react_wrappers.dart
smaifullerton-wk Jul 29, 2020
a35d59f
Merge pull request #454 from Workiva/improve-forwardref-documentation
smaifullerton-wk Jul 29, 2020
c542033
Add extension method
joebingham-wk Jul 30, 2020
34dfe02
Add export and address doc comment nit
smaifullerton-wk Jul 30, 2020
d937e52
Merge pull request #613 from Workiva/cplat-9347-add-memo-hoc
rmconsole6-wk Jul 30, 2020
ca6ed4f
Remove namespace from example import
aaronlademann-wf Jul 31, 2020
0a89432
Merge pull request #614 from Workiva/fix-example-typos
rmconsole7-wk Jul 31, 2020
841d102
Add tests
joebingham-wk Aug 3, 2020
117cadb
Format tests
joebingham-wk Aug 3, 2020
68f4700
Merge in base
joebingham-wk Aug 3, 2020
96ba4ff
Clean up
joebingham-wk Aug 3, 2020
de94787
Rename FunctionComponentConfig to UiFactoryConfig
joebingham-wk Aug 3, 2020
b9634df
Update builder readme to reflect new codegen
greglittlefield-wf Aug 3, 2020
ea10a41
Check for generated config
joebingham-wk Aug 3, 2020
7a25a19
Apply suggestions from code review
greglittlefield-wf Aug 3, 2020
6753fef
Merge pull request #615 from Workiva/builder-readme
rm-astro-wf Aug 4, 2020
1c56416
Update uiFunction documentation
smaifullerton-wk Aug 4, 2020
d435a1f
Fix parsing
joebingham-wk Aug 4, 2020
d865b24
Fix up example
joebingham-wk Aug 5, 2020
378a58d
Fix CI
joebingham-wk Aug 5, 2020
7d288eb
Fix breakages from analyzer 0.39.16
joebingham-wk Aug 5, 2020
861fda7
Format
joebingham-wk Aug 5, 2020
fa6eb84
Address feedback
joebingham-wk Aug 6, 2020
1de88bb
Revert unintentional change
joebingham-wk Aug 6, 2020
d66db3f
Fix empty name issue
joebingham-wk Aug 6, 2020
0e3f5ef
Revert change to getFunctionName
joebingham-wk Aug 6, 2020
236f344
Fix doc comment
joebingham-wk Aug 6, 2020
ac8a42c
Improve example logging readability
joebingham-wk Aug 6, 2020
9e3f6d3
Improve deprecation doc comment
joebingham-wk Aug 6, 2020
e5001d2
Address parser feedback
joebingham-wk Aug 6, 2020
8189f1c
Fix up example
joebingham-wk Aug 7, 2020
49df84c
Add integration tests
joebingham-wk Aug 7, 2020
acf2582
Format
joebingham-wk Aug 7, 2020
af9e2e4
Update doc comment
joebingham-wk Aug 7, 2020
31b3414
Address more feedback :tada:
joebingham-wk Aug 7, 2020
b0f9877
Add displayName to doc comment
joebingham-wk Aug 7, 2020
d12bca5
Fix example title
joebingham-wk Aug 7, 2020
4ff4b37
Merge pull request #612 from Workiva/CPLAT-11722-add-uiForwardRef
rmconsole2-wf Aug 7, 2020
7921121
Bump lower bound of react dependency to 5.5.0
aaronlademann-wf Aug 7, 2020
5066bbf
Address forwardRef deprecations
aaronlademann-wf Aug 7, 2020
12306d9
Update version / changelog for over_react 3.8.0
aaronlademann-wf Aug 7, 2020
72854b3
Update over_react version in plugin pubspec
aaronlademann-wf Aug 7, 2020
8bb0349
Remove confusing comment
aaronlademann-wf Aug 7, 2020
3691f8e
Update uiForwardRef examples
aaronlademann-wf Aug 7, 2020
cb1ab3c
Minor updates from function components blog post reviews
smaifullerton-wk Aug 7, 2020
aca6b05
Generate function component example
aaronlademann-wf Aug 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# OverReact Changelog

## [3.8.0](https://github.com/Workiva/over_react/compare/3.7.0...3.8.0)

__New Features__

- 🎉 🎉 🎉 __Support for function components, memo and hooks!!!__ 🎉 🎉 🎉

Sooooo much work from so many amazing people made this possible, but to summarize:

- [#606] Add support for function components
- [#613] Add support for `memo` higher order component
- [#611] Hooks, hooks, and more hooks!
- useState
- useCallback
- useContext
- useEffect
- useLayoutEffect
- useReducer
- useRef
- useMemo
- useImperativeHandle
- useDebugValue

<p><br>It works like this...</p>

Define the component
```dart
mixin FancyBorderProps on UiProps {
String color;
}

UiFactory<FancyBorderProps> FancyBorder = uiFunction(
(props) {
// props is typed as a `FancyBorderProps`
// whatever you return here will be rendered
return (Dom.div()..className = 'fancy-border border-${props.color}')(
props.children,
);
},
$FancyBorderConfig, // ignore: undefined_identifier
);
```

Render the component _(exact same consumer API as a class-based component)_:
```dart
import 'package:over_react/over_react.dart';
import 'fancy_border.dart'; // Where your component is defined

main() {
final renderedWidget = (FancyBorder()..color = /* some color value */)(
// put some children here!
);

react_dom.render(renderedWidget, querySelector('#idOfSomeNodeInTheDom'));
}
```

__Other Changes__

- [#612] Deprecate `forwardRef` / add `uiForwardRef` as its replacement


## [3.7.0](https://github.com/Workiva/over_react/compare/3.6.0...3.7.0)

__Library Changes:__
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,36 @@ that you get for free from OverReact, you're ready to start building your own cu
}
}
```

* #### Function Component Boilerplate

```dart
import 'package:over_react/over_react.dart';
part 'foo_component.over_react.g.dart';

UiFactory<FooProps> Foo = uiFunction(
(props) {
// Set default props using null-aware operators.
final isDisabled = props.isDisabled ?? false;
final items = props.items ?? [];

// Return the rendered component contents here.
// The `props` variable is typed; no need for string keys!
return Fragment()(
Dom.div()(items),
(Dom.button()..disabled = isDisabled)('Click me!'),
);
},
// The generated props config will match the factory name.
$FooConfig, // ignore: undefined_identifier
);

mixin FooProps on UiProps {
// Props go here, declared as fields:
bool isDisabled;
Iterable<String> items;
}
```

&nbsp;

Expand Down
60 changes: 49 additions & 11 deletions doc/new_boilerplate_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ Most code within over_react has been updated to use this new boilerplate, includ
- The Redux sample todo app under [`app/over_react_redux/todo_client/`](../app/over_react_redux/todo_client)


## Function Component Boilerplate _(coming soon)_
## Function Component Boilerplate

### Function Component Constraints

Expand All @@ -727,22 +727,22 @@ import 'package:over_react/over_react.dart';

part 'foo.over_react.g.dart';

UiFactory<FooProps> Foo = uiFunctionComponent(
UiFactory<FooProps> Foo = uiFunction(
(props) {
return 'foo: ${props.foo}';
},
$fooPropsConfig, // ignore: undefined_identifier
$FooConfig, // ignore: undefined_identifier
);

mixin FooProps on UiProps {
String foo;
}
```

Here, `uiFunctionComponent` gets a generic parameter of `FooProps` inferred
Here, `uiFunction` gets a generic parameter of `FooProps` inferred
from the LHS typing, allowing props to be statically typed as `FooProps`.

The generated `$FooPropsConfig` is passed in as an argument, and serves
The generated `$FooConfig` is passed in as an argument, and serves
as the entrypoint to the generated code.

#### With Default Props
Expand All @@ -755,24 +755,37 @@ same behavior as `defaultProps`, but with the restriction that a given prop
__must either be nullable or have a default value, but not both__.

```dart
UiFactory<FooProps> Foo = uiFunctionComponent(
UiFactory<FooProps> Foo = uiFunction(
(props) {
final foo = props.foo ?? 'default foo value';

return 'foo: $foo';
},
$fooPropsConfig, // ignore: undefined_identifier
$FooConfig, // ignore: undefined_identifier
);
```

#### With UiProps

```dart
UiFactory<UiProps> Foo = uiFunction(
(props) {
return 'id: ${props.id}';
},
UiFactoryConfig(
displayName: 'Foo',
),
);
```

#### With propTypes

```dart
UiFactory<FooProps> Foo = uiFunctionComponent(
UiFactory<FooProps> Foo = uiFunction(
(props) {
return 'foo: ${props.foo}';
},
$fooPropsConfig, // ignore: undefined_identifier
$FooConfig, // ignore: undefined_identifier
getPropTypes: (keyFor) => {
keyFor((p) => p.foo): (props, info) {
if (props.foo == 'bar') {
Expand Down Expand Up @@ -803,20 +816,45 @@ UiFactory<FooProps> createFooHoc(UiFactory otherFactory) {
Object closureVariable;
// ...

final FooHoc = uiFunctionComponent<FooProps>(
UiFactory<FooProps> FooHoc = uiFunction(
(props) {
return otherFactory()(
Dom.div()('closureVariable: ${closureVariable}'),
Dom.div()('prop foo: ${props.foo}'),
);
},
$fooPropsConfig, // ignore: undefined_identifier
UiFactoryConfig(
displayName: 'FooHoc',
propsFactory: PropsFactory.fromUiFactory(Foo),
),
);

return FooHoc;
}
```

#### With forwardRef

```dart
mixin FooProps on UiProps {
Ref forwardedRef;
Function doSomething;
}

UiFactory<FooProps> Foo = uiForwardRef(
(props, ref) {
return Fragment()(
Dom.div()('Some text.'),
(Dom.button()
..ref = ref
..onClick = props.doSomething
)('Click me!'),
);
},
$FooConfig, // ignore: undefined_identifier
);
```

## Upgrading Existing Code

To update your repository to the new boilerplate, you can use
Expand Down
3 changes: 3 additions & 0 deletions example/builder/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './src/basic.dart';
import './src/basic_library.dart';
import './src/generic_inheritance_sub.dart';
import './src/generic_inheritance_super.dart';
import './src/function_component.dart' as function;

main() {
setClientConfiguration();
Expand Down Expand Up @@ -52,6 +53,8 @@ main() {
..subProp = 'sub prop part of lib'
..superProp = 'super prop part of lib'
)(),
Dom.h3()('Function component:'),
function.functionComponentContent(),
Dom.h3()('getDefaultProps via component factories'),
componentConstructorsByName.keys.map((name) => Dom.div()(
'new $name()',
Expand Down
106 changes: 106 additions & 0 deletions example/builder/src/function_component.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2020 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:over_react/over_react.dart';

// ignore_for_file: uri_has_not_been_generated
part 'function_component.over_react.g.dart';

mixin BasicProps on UiProps {
Ref forwardedRef;
String basicProp;
String basic1;
String basic2;
String basic3;
String basic4;
}

UiFactory<BasicProps> Basic = uiForwardRef(
(props, ref) {
return Fragment()(
Dom.div()('prop id: ${props.id}'),
Dom.div()('default prop testing: ${props.basicProp}'),
Dom.div()('default prop testing: ${props.basic1}'),
(Dom.div()..ref = ref)(
props.basic3, 'children: ${props.children}'),
);
},
$BasicConfig, // ignore: undefined_identifier
);

UiFactory<BasicProps> Simple = uiFunction(
(props) {
final basicProp = props.basicProp ?? 'basicProp';
final basic1 = props.basic1 ?? 'basic1';

return Fragment()(
Dom.div()('prop id: ${props.id}'),
Dom.div()('default prop testing: $basicProp'),
Dom.div()('default prop testing: $basic1'),
Dom.div()(null, props.basic4, 'children: ${props.children}'),
(Foo()..content = props.basic2)(),
);
},
$SimpleConfig, // ignore: undefined_identifier
);

mixin FooProps on UiProps {
String content;
}

UiFactory<FooProps> Foo = uiFunction(
(props) => Dom.div()('forwarded prop: ${props.content}'),
$FooConfig, // ignore: undefined_identifier
);

ReactElement functionComponentContent() {
GenericFactory(props) {
return Dom.div()('prop id: ${props.id}');
}

UiFactory<UiProps> genericFactory = uiFunction(
GenericFactory,
UiFactoryConfig(),
);

UiFactory<BasicProps> basicFactory = uiFunction(
(props) {
return Fragment()(
Dom.div()('prop id: ${props.id}'),
Dom.div()('prop basic1: ${props.basic1}'),
);
},
UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Basic),
displayName: 'basicFactory',
)
);

// Access the div element later using `divRef.current`.
Ref divRef = createRef();

return Fragment()(
(genericFactory()..id = '1')(),
(basicFactory()
..id = '2'
..basic1 = 'basic1 value')(),
(Basic()
..ref = divRef
..id = '3'
..basicProp = 'basicProp')(),
(Simple()
..id = '4'
..basic2 = 'basic2 value')(),
);
}
Loading