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-3873 Function Components #606

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
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
59e8d8e
Update function name and doc comments
sydneyjodon-wk Jul 22, 2020
b759f8a
Update migration guide examples
sydneyjodon-wk Jul 22, 2020
cec79b9
Update based on reviewer feedback
sydneyjodon-wk 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
0fd444a
Update generic args for uiFunction
sydneyjodon-wk Jul 24, 2020
e7a263d
Update uiFunction args
sydneyjodon-wk Jul 24, 2020
c22f0a2
Address feedback
sydneyjodon-wk Jul 27, 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
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,22 @@ that you get for free from OverReact, you're ready to start building your own cu
import 'package:over_react/over_react.dart';
part 'foo_component.over_react.g.dart';

UiFactory<FooProps> Foo = uiFunctionComponent((props) {
// Return the rendered component contents here.
// The `props` variable is typed; no need for string keys!
},
// The generated props config will match the factory name.
$FooPropsConfig,
initStatics: (statics) {
statics.defaultProps = (statics.newProps()
// Cascade default props here.
..isDisabled = false
..items = []
);
});
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:
Expand Down
63 changes: 52 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(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The RFD used both names for this function. uiFunction was what the ticket said to name it, but if anyone thinks it should be uiFunctionComponent I can update it.

(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,35 @@ 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}';
},
null,
);
```

#### 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 +814,50 @@ UiFactory<FooProps> createFooHoc(UiFactory otherFactory) {
Object closureVariable;
// ...

final FooHoc = uiFunctionComponent<FooProps>(
final FooHoc = uiFunction<FooProps>(
sydneyjodon-wk marked this conversation as resolved.
Show resolved Hide resolved
(props) {
return otherFactory()(
Dom.div()('closureVariable: ${closureVariable}'),
Dom.div()('prop foo: ${props.foo}'),
);
},
$fooPropsConfig, // ignore: undefined_identifier
null,
propsFactory: PropsFactory.fromUiFactory(Foo),
);

return FooHoc;
}
```

#### With forwardRef

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

UiFactory<FooProps> Foo = forwardRef<FooProps>((props, ref) {
return (_Foo()
..forwardedRef = ref
..doSomething = props.doSomething
)();
})(_Foo);

UiFactory<FooProps> _Foo = uiFunction(
(props) {
return Fragment()(
Dom.div()('Some text.'),
(Dom.button()
..ref = props.forwardedRef
..onClick = props.doSomething
)('Click me!'),
);
},
$_FooConfig, // ignore: undefined_identifier
);
sydneyjodon-wk marked this conversation as resolved.
Show resolved Hide resolved
```

## Upgrading Existing Code

To update your repository to the new boilerplate, you can use
Expand Down
Loading