-
Notifications
You must be signed in to change notification settings - Fork 58
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
Changes from 32 commits
dd8bb52
a81cdf8
8e2d970
d773544
86bc327
6958e22
7dc77f6
027cd66
3e62161
e2da213
42005e2
685e9d7
659692e
1d614a9
f57ea6c
68db3d4
d9d0708
d71da40
4885e6b
b19542c
49d1f5e
27bc400
3828257
6fa267e
0a4d434
9ef8829
a2d31b2
e43751a
f99e40d
3a2daeb
59e8d8e
b759f8a
cec79b9
f117e9d
d1c01d7
eaa69ca
0e38d4d
82f92a4
0fd444a
e7a263d
c22f0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -727,19 +727,19 @@ import 'package:over_react/over_react.dart'; | |
|
||
part 'foo.over_react.g.dart'; | ||
|
||
UiFactory<FooProps> Foo = uiFunctionComponent( | ||
UiFactory<FooProps> Foo = uiFunction( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The RFD used both names for this function. |
||
(props) { | ||
return 'foo: ${props.foo}'; | ||
}, | ||
$fooPropsConfig, // ignore: undefined_identifier | ||
$FooPropsConfig, // 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 | ||
|
@@ -755,24 +755,24 @@ 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 | ||
$FooPropsConfig, // ignore: undefined_identifier | ||
); | ||
``` | ||
|
||
#### With propTypes | ||
|
||
```dart | ||
UiFactory<FooProps> Foo = uiFunctionComponent( | ||
UiFactory<FooProps> Foo = uiFunction( | ||
(props) { | ||
return 'foo: ${props.foo}'; | ||
}, | ||
$fooPropsConfig, // ignore: undefined_identifier | ||
$FooPropsConfig, // ignore: undefined_identifier | ||
getPropTypes: (keyFor) => { | ||
keyFor((p) => p.foo): (props, info) { | ||
if (props.foo == 'bar') { | ||
|
@@ -803,14 +803,14 @@ 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 | ||
$FooPropsConfig, // ignore: undefined_identifier | ||
); | ||
|
||
return FooHoc; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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'; | ||
import 'package:react/react_client.dart'; | ||
import 'package:react/react_client/react_interop.dart'; | ||
sydneyjodon-wk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// ignore_for_file: uri_has_not_been_generated | ||
part 'function_component.over_react.g.dart'; | ||
|
||
mixin BasicProps on UiProps { | ||
String basicProp; | ||
String basic1; | ||
String basic2; | ||
String basic3; | ||
String basic4; | ||
} | ||
|
||
UiFactory<BasicProps> Basic = uiFunction((props) { | ||
return Fragment()( | ||
Dom.div()('prop id: ${props.id}'), | ||
Dom.div()('default prop testing: ${props.basicProp}'), | ||
Dom.div()('default prop testing: ${props.basic1}'), | ||
Dom.div()(props.basic3, 'children: ${props.children}'), | ||
); | ||
}, $BasicPropsConfig); | ||
|
||
final Simple = uiFunction<BasicProps>((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}'), | ||
); | ||
}, $SimplePropsConfig); | ||
|
||
ReactElement functionComponentContent() { | ||
GenericFactory(props) { | ||
return Dom.div()('prop id: ${props.id}'); | ||
} | ||
final genericFactory = uiFunction<UiProps>(GenericFactory, null); | ||
|
||
final basicFactory = uiFunction<BasicProps>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we should also have one utilizing |
||
(props) { | ||
return Fragment()( | ||
Dom.div()('prop id: ${props.id}'), | ||
Dom.div()('prop basic1: ${props.basic1}'), | ||
); | ||
}, | ||
null, | ||
propsFactory: PropsFactory.fromUiFactory(Basic), | ||
displayName: 'basicFactory', | ||
); | ||
|
||
return Fragment()( | ||
(genericFactory()..id = '1')(), | ||
(basicFactory() | ||
..id = '2' | ||
..basic1 = 'basic1 value')(), | ||
(Basic() | ||
..id = '3' | ||
..basicProp = 'basicProp')(), | ||
(Simple()..id = '4')(), | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return something here to demonstrate things like prop forwarding, etc.?