Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e72ba79
inital pass at function components
kealjones-wk Oct 24, 2019
d5c2768
format
kealjones-wk Oct 24, 2019
e1f4046
fix JsFunctionComponent type signature
kealjones-wk Oct 24, 2019
7a470c9
format
kealjones-wk Oct 24, 2019
f1bf6ea
add interop for js null
kealjones-wk Oct 24, 2019
066c9b3
address early pr feedback
kealjones-wk Oct 24, 2019
a04508f
format
kealjones-wk Oct 24, 2019
d60b834
cleanup
kealjones-wk Oct 24, 2019
3ac59ba
mainly to trigger re-build
kealjones-wk Oct 25, 2019
a6d635c
Merge branch '5.1.0-wip' into CPLAT-3874-function-components
kealjones-wk Oct 25, 2019
7b4c28f
cleanup tests
kealjones-wk Oct 25, 2019
71f7cf9
format
kealjones-wk Oct 25, 2019
089b320
Apply suggestions from code review
kealjones-wk Oct 29, 2019
dd979ac
address CR feedback
kealjones-wk Oct 29, 2019
61f15f3
format
kealjones-wk Oct 29, 2019
bbf4e15
update variable declarations to "const"s
kealjones-wk Oct 29, 2019
7bd9547
fix formatting of js files
kealjones-wk Oct 29, 2019
5446a50
revert comment
kealjones-wk Oct 29, 2019
5f6c05e
Apply suggestions from code review
kealjones-wk Oct 29, 2019
2838077
Update lib/react_client.dart
kealjones-wk Oct 29, 2019
d48757b
add function component link to example page
kealjones-wk Oct 29, 2019
fb26d5c
Merge branch 'CPLAT-3874-function-components' of https://github.com/c…
kealjones-wk Oct 29, 2019
5c86967
update function component example
kealjones-wk Oct 29, 2019
c0d6ae7
address cr feedback
kealjones-wk Nov 1, 2019
e685462
revert some changes and cleanup
kealjones-wk Nov 1, 2019
cb8c4db
remove unused field and annotate overrides
kealjones-wk Nov 1, 2019
aaba9cb
remove accidental test name
kealjones-wk Nov 1, 2019
64d9fa4
cleanup comments
kealjones-wk Nov 1, 2019
756c022
address more feedback
kealjones-wk Nov 1, 2019
d984513
remove unused import
kealjones-wk Nov 1, 2019
c819a93
remove newline
kealjones-wk Nov 1, 2019
fc40326
fix formatting
kealjones-wk Nov 4, 2019
fa7a630
address cr feedback
kealjones-wk Nov 4, 2019
52186c8
Apply suggestions from code review
kealjones-wk Nov 4, 2019
dd48b08
fix map infurence in context example
kealjones-wk Nov 5, 2019
bf0251e
Merge branch 'CPLAT-3874-function-components' of https://github.com/c…
kealjones-wk Nov 5, 2019
5d721bb
fix doc comments
kealjones-wk Nov 5, 2019
1852701
Fix confusing owner test utils and unnecessary isComponent2 flag
greglittlefield-wf Nov 5, 2019
1c89e35
fix formatting
kealjones-wk Nov 5, 2019
40b9ef2
refactor displayName and add tests
kealjones-wk Nov 5, 2019
2092d76
merge 5.1.0
kealjones-wk Nov 5, 2019
0a453d8
re-sync with 5.2.0-wip
kealjones-wk Nov 5, 2019
59de7c6
Merge branch '5.2.0-wip' into CPLAT-3874-function-components
kealjones-wk Nov 5, 2019
b69ba40
unify FactoryProxy build methods
kealjones-wk Nov 5, 2019
b38fb99
update _generateChildren to handle Iterables
kealjones-wk Nov 6, 2019
faadc30
Update comment for registerFunctionComponent
kealjones-wk Nov 6, 2019
a8db14c
format
kealjones-wk Nov 6, 2019
213b47d
organize imports
kealjones-wk Nov 6, 2019
01e65a8
update doc comment for JsFunctionComponent
kealjones-wk Nov 6, 2019
5504aa9
Merge branch '5.2.0-wip' into CPLAT-3874-function-components
kealjones-wk Nov 13, 2019
af630c7
Apply suggestions from code review
kealjones-wk Nov 13, 2019
1834105
fix bad merge
kealjones-wk Nov 13, 2019
3929947
exclude function name test due to 2.4.1
kealjones-wk Nov 13, 2019
3242857
remove periods because linux
kealjones-wk Nov 13, 2019
a6278e0
fix 241 on release
kealjones-wk Nov 13, 2019
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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ before_script:
- pub run dependency_validator -i build_runner,build_test,build_web_compilers

script:
- pub run build_runner test --release -- -p chrome
- pub run build_runner test -- -p chrome
# TODO once production is above 2.4.1 re-check the `fails-on-2.4.1` tagged tests
- pub run build_runner test --release -- -p chrome -x fails-on-241
- pub run build_runner test -- -p chrome -x fails-on-241
2 changes: 2 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags:
"fails-on-241":
3 changes: 3 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ <h2 class="display-5">Use Case / Test Examples</h2>
<li>
<a href="js_components/index.html"><code>JsComponents</code> Example</a>
</li>
<li>
<a href="test/function_component_test.html"><code>Function Component</code> test</a>
</li>
</ul>

</div>
Expand Down
34 changes: 34 additions & 0 deletions example/test/function_component_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:html';

import 'package:react/react.dart' as react;
import 'package:react/react_dom.dart' as react_dom;
import 'package:react/react_client.dart';

import 'react_test_components.dart';

void main() {
setClientConfiguration();
var inputValue = 'World';
// TODO: replace this with hooks/useState when they are added.
render() {
react_dom.render(
react.Fragment({}, [
react.input(
{
'defaultValue': inputValue,
'onChange': (event) {
inputValue = event.currentTarget.value;
render();
}
},
),
react.br({}),
helloGregFunctionComponent({'key': 'greg'}),
react.br({}),
helloGregFunctionComponent({'key': 'not greg'}, inputValue)
]),
querySelector('#content'));
}

render();
}
17 changes: 17 additions & 0 deletions example/test/function_component_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<title>React Dart Examples: function component test</title>
</head>
<body>
<div id="content" class="container"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="function_component_test.dart.js"></script>
</body>
</html>
14 changes: 12 additions & 2 deletions example/test/react_test_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ class _NewContextProviderComponent extends react.Component2 {
}

render() {
Map provideMap = {'renderCount': this.state['renderCount']};
final provideMap = {'renderCount': this.state['renderCount']};

Map complexValues = {
final complexValues = {
'callback': printMe,
'dartComponent': newContextRefComponent,
'map': {
Expand Down Expand Up @@ -393,6 +393,16 @@ class _NewContextTypeConsumerComponent extends react.Component2 {
}
}

var helloGregFunctionComponent = react.registerFunctionComponent(HelloGreg);

HelloGreg(Map props) {
var content = ['Hello Greg!'];
if (props['children'].isNotEmpty) {
content = ['Hello ' + props['children'].join(' ') + '!'];
}
return react.Fragment({}, content);
}

class _Component2TestComponent extends react.Component2 with react.TypedSnapshot<String> {
get defaultProps => {'defaultProp': true};

Expand Down
17 changes: 12 additions & 5 deletions js_src/_dart_helpers.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
/**
* react-dart JS interop helpers (used by react_client.dart and react_client/js_interop_helpers.dart)
*/

/// Prefix to namespace react-dart symbols
var _reactDartSymbolPrefix = 'react-dart.';
const _reactDartSymbolPrefix = 'react-dart.';

/// A global symbol to identify javascript objects owned by react-dart context,
/// in order to jsify and unjsify context objects correctly.
var _reactDartContextSymbol = Symbol(_reactDartSymbolPrefix+'context');
const _reactDartContextSymbol = Symbol(_reactDartSymbolPrefix + 'context');

/// A JS side function to allow Dart to throw an error from JS in order to catch it Dart side.
/// Used within Component2 error boundry methods to dartify the error argument.
/// See: https://github.com/dart-lang/sdk/issues/36363
function _throwErrorFromJS(error){
function _throwErrorFromJS(error) {
throw error;
}

/// A JS variable that can be used with Fart interop in order to force returning a
/// JavaScript `null`. This prevents dart2js from possibly converting Dart `null` into `undefined`.
const _jsNull = null;

function _createReactDartComponentClass(dartInteropStatics, componentStatics, jsConfig) {
class ReactDartComponent extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -131,7 +137,7 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
}

// Delete methods that the user does not want to include (such as error boundary event).
jsConfig.skipMethods.forEach((method) => {
jsConfig.skipMethods.forEach(method => {
if (ReactDartComponent2[method]) {
delete ReactDartComponent2[method];
} else {
Expand Down Expand Up @@ -165,4 +171,5 @@ export default {
_createReactDartComponentClass2,
_markChildValidated,
_throwErrorFromJS,
}
_jsNull,
};
62 changes: 61 additions & 1 deletion lib/react.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export 'package:react/src/context.dart';
export 'package:react/src/prop_validator.dart';
export 'package:react/react_client/react_interop.dart' show forwardRef, createRef;

typedef Error PropValidator<TProps>(TProps props, PropValidatorInfo info);

/// A React component declared using a function that takes in [props] and returns rendered output.
///
/// See <https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components>.
typedef DartFunctionComponent = dynamic Function(Map props);

typedef T ComponentFactory<T extends Component>();

typedef ReactComponentFactoryProxy ComponentRegistrar(ComponentFactory componentFactory,
[Iterable<String> skipMethods]);

Expand All @@ -29,6 +37,9 @@ typedef ReactDartComponentFactoryProxy2 ComponentRegistrar2(
Component2BridgeFactory bridgeFactory,
});

typedef ReactDartFunctionComponentFactoryProxy FunctionComponentRegistrar(DartFunctionComponent componentFactory,
{String displayName});

/// Fragment component that allows the wrapping of children without the necessity of using
/// an element that adds an additional layer to the DOM (div, span, etc).
///
Expand Down Expand Up @@ -1210,6 +1221,23 @@ mixin TypedSnapshot<TSnapshot> {

/// Creates a ReactJS virtual DOM instance (`ReactElement` on the client).
abstract class ReactComponentFactoryProxy implements Function {
/// The JS component factory used by this factory to build [ReactElement]s.
///
/// Deprecated: Use [React.createElement()] instead and pass in [type] as
/// the first argument, followed by `props` and `children`.
///
/// Before:
/// ```
/// YourFactoryProxy.reactComponentFactory(props, children);
/// ```
///
/// After:
/// ```
/// React.createElement(YourFactoryProxy.type, props, children);
/// ```
@Deprecated('6.0.0')
ReactJsComponentFactory reactComponentFactory;

/// The type of component created by this factory.
get type;

Expand Down Expand Up @@ -1790,6 +1818,32 @@ ComponentRegistrar2 registerComponent2 = (
throw new Exception('setClientConfiguration must be called before registerComponent.');
};

/// Registers [componentFactory] on client.
///
/// Example:
/// ```
/// var myFunctionComponent = registerFunctionComponent((Map props) {
/// return ['I am a function component', ...props.children];
/// });
/// ```
///
/// Example with display name:
/// ```
/// var myFunctionComponent = registerFunctionComponent((Map props) {
/// return ['I am a function component', ...props.children];
/// }, displayName: 'myFunctionComponent');
/// ```
/// or with an inferred name from the Dart function
/// ```
/// myDartFunctionComponent(Map props) {
/// return ['I am a function component', ...props.children];
/// }
/// var myFunctionComponent = registerFunctionComponent(myDartFunctionComponent);
/// ```
FunctionComponentRegistrar registerFunctionComponent = (DartFunctionComponent componentFactory, {String displayName}) {
throw new Exception('setClientConfiguration must be called before registerFunctionComponent.');
};

/// The HTML `<a>` [AnchorElement].
var a;

Expand Down Expand Up @@ -2594,9 +2648,15 @@ _createDOMComponents(creator) {
///
/// The arguments are assigned to global variables, and React DOM `Component`s are created by calling
/// [_createDOMComponents] with [domCreator].
void setReactConfiguration(domCreator, customRegisterComponent, {ComponentRegistrar2 customRegisterComponent2}) {
void setReactConfiguration(
domCreator,
customRegisterComponent, {
ComponentRegistrar2 customRegisterComponent2,
FunctionComponentRegistrar customRegisterFunctionComponent,
}) {
registerComponent = customRegisterComponent;
registerComponent2 = customRegisterComponent2;
registerFunctionComponent = customRegisterFunctionComponent;
// HTML Elements
_createDOMComponents(domCreator);
}
9 changes: 7 additions & 2 deletions lib/react.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react.js.map

Large diffs are not rendered by default.

Loading