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-4303: React 16 New Context #160

Merged
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f84c15d
Deprecate js_interop_helpers in favor of package:js/js_util.dart
greglittlefield-wf Dec 29, 2016
0713393
Un-deprecate jsify, fix deprecations
greglittlefield-wf Dec 29, 2016
77f9b91
Bump JS package version to the one that exposes js_util.dart
greglittlefield-wf Dec 30, 2016
bfc53e5
Revert likely breaking change to emptyJsMap and deprecate it instead
greglittlefield-wf Dec 30, 2016
68008b4
Merge branch 'use_js_util' into js_components
greglittlefield-wf Dec 30, 2016
4a16ba4
Add common factory tests for DOM/Dart components
greglittlefield-wf Dec 30, 2016
c174de2
Add factory proxy for JS components
greglittlefield-wf Dec 30, 2016
86913c2
Add JS factory tests
greglittlefield-wf Dec 30, 2016
f93f521
Add jsifyAndAllowInterop, deprecate jsify
greglittlefield-wf Dec 30, 2016
c346708
Use jsifyAndAllowInterop
greglittlefield-wf Dec 30, 2016
f20c287
Clean up simulators slightly
greglittlefield-wf Dec 30, 2016
1a7b5ff
By default, convert DOM props passed to JS components
greglittlefield-wf Dec 30, 2016
e107f93
Throw if backing JS class is null
greglittlefield-wf Jan 2, 2017
992586e
Add common event handler tests
greglittlefield-wf Jan 2, 2017
cd9d840
Add wrapEventHandler convenience method
greglittlefield-wf Jan 2, 2017
f0c12fe
Add demo on using JS components
greglittlefield-wf Jan 2, 2017
56b1d4b
Add index to example directory
greglittlefield-wf Jan 2, 2017
63ab345
Add notice about seeing Dart source
greglittlefield-wf Jan 2, 2017
e7209e6
Include full dart-lang/sdk license text in attribution
greglittlefield-wf Jan 2, 2017
273b915
Merge remote-tracking branch 'origin/master' into js_components
greglittlefield-wf Feb 19, 2019
8f50741
Fix lints
greglittlefield-wf Feb 19, 2019
dd34bad
Post-merge fixes
greglittlefield-wf Feb 19, 2019
0f38687
dartfmt
greglittlefield-wf Feb 19, 2019
e611912
Fix example
greglittlefield-wf Feb 19, 2019
2a44115
inital pass at new context
kealjones-wk Feb 19, 2019
c358278
Fix js_factory_test.js div creation
kealjones-wk Feb 20, 2019
5a8768d
ReactJsComponentFactoryProxy is WORKING!
kealjones-wk Feb 26, 2019
9967b32
Merge branch 'master' into react-16-new-context
kealjones-wk Feb 27, 2019
785615e
Fix contextType in release mode and Update tests
kealjones-wk Feb 27, 2019
06ebacf
Update contextType to getter/setter to get doc comment to showing
kealjones-wk Feb 27, 2019
fe505af
Add tests for context value types
kealjones-wk Feb 28, 2019
22c4e8b
remove unused imports from new tests
kealjones-wk Feb 28, 2019
d86c53b
Merge 5.0.0-wip
kealjones-wk Feb 28, 2019
57d8396
cleanup and run dartfmt
kealjones-wk Feb 28, 2019
dc57dd4
push updated bundles
kealjones-wk Feb 28, 2019
a56e1a7
Dart1 Compatability fixes
kealjones-wk Feb 28, 2019
e2863ed
more dart 1 compat stuff
kealjones-wk Feb 28, 2019
33b8e67
ignore .vscode :|
kealjones-wk Feb 28, 2019
8c96836
Address CR Feedback
kealjones-wk Mar 4, 2019
5c21ac8
Add new context to Component2
kealjones-wk Mar 16, 2019
1351180
undo changes to JsBackedMap and update tests
kealjones-wk Mar 16, 2019
cb748ff
fix dart js
kealjones-wk Mar 17, 2019
eca1297
Cleanup and address some feedback
kealjones-wk Mar 17, 2019
06e0657
dart format 120 and js package update
kealjones-wk Mar 17, 2019
a4ab9f9
Merge 5.0.0-wip
kealjones-wk Mar 17, 2019
752150e
remove typing from interop, due to strange issue it created
kealjones-wk Mar 17, 2019
e6e5374
Undo some type loosening
kealjones-wk Mar 18, 2019
3668628
fix context example
kealjones-wk Mar 18, 2019
40f96b7
fix dartfmt
kealjones-wk Mar 18, 2019
063b8f1
fix react dev tools and tests
kealjones-wk Mar 18, 2019
a90610b
re-add legacy context to example
kealjones-wk Mar 18, 2019
e2629f4
dartfmt
kealjones-wk Mar 18, 2019
a706cda
change usages of js_interop_helpers.dart to dart:js_util and more
kealjones-wk Mar 18, 2019
ce8b15d
dartfmt
kealjones-wk Mar 18, 2019
5c6e73c
update to better support calculateChangedBits
kealjones-wk Mar 19, 2019
cec53a5
dartfmt
kealjones-wk Mar 19, 2019
11a98f2
add tests for createContext calculateChangedBits
kealjones-wk Mar 19, 2019
5f25108
re-order wrappers to top of components
kealjones-wk Mar 19, 2019
42c7f1f
Fix some interop issues when using dart2js
kealjones-wk Mar 19, 2019
95863b5
add shouldComponentUpdate with 3rd argument
kealjones-wk Mar 20, 2019
b16a8bc
dartfmt
kealjones-wk Mar 20, 2019
4044e5c
addressing more cr feedback
kealjones-wk Mar 20, 2019
b85d5ff
Merge 5.0.0-wip resolve merge conflicts
kealjones-wk Mar 20, 2019
0b60aab
dartfmt
kealjones-wk Mar 20, 2019
9fd46f8
Update js Components example and add link
kealjones-wk Mar 20, 2019
f3353e4
Merge ‘upstream/5.0.0-wip' into react-16-new-context
aaronlademann-wf Mar 21, 2019
e26827d
Update Js Example to use some Material UI Components
kealjones-wk Mar 22, 2019
745a0b7
Address some CR feedback by aaron
kealjones-wk Mar 22, 2019
71bf2ca
address more feedback
kealjones-wk Mar 25, 2019
34b95cc
add small comments to example
kealjones-wk Mar 25, 2019
f3ad312
Address CR Feedback
kealjones-wk Apr 1, 2019
d38c570
address cr and Add contextType Lifecycle tests
kealjones-wk Apr 3, 2019
45ed03a
Update build config for dart2js, use build_runner to run dart2js tests
greglittlefield-wf Apr 2, 2019
bb67481
Update typing, remove redundant `as dynamic` JsBackedMap case
greglittlefield-wf Apr 3, 2019
bd28d30
add a context.consumer child lifecycle test
kealjones-wk Apr 3, 2019
81dc26a
Merge pull request #3 from greglittlefield-wf/react-16-new-context
kealjones-wk Apr 3, 2019
9d6045b
dartfmt
kealjones-wk Apr 3, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pubspec.lock
.packages
node_modules/
.dart_tool
.vscode
3 changes: 3 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ <h2 class="display-5">Use Case / Test Examples</h2>
<li>
<a href="test/unmount_test.html"><code>unmountComponentAtNode</code> test</a>
</li>
<li>
<a href="js_components/index.html"><code>JsComponents</code> Example</a>
</li>
</ul>

</div>
Expand Down
33 changes: 33 additions & 0 deletions example/js_components/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>JS Components - react-dart Examples</title>
<style>
#content {
width: 100%;
height: 100%;
text-align: center;
}
</style>
</head>
<body>
<em>See Dart source for more info</em>

<div id="content"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="https://unpkg.com/@material-ui/core/umd/material-ui.development.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<!-- This Babel script could be replaced with a webpack or some other build process -->
<script src="https://unpkg.com/babel-standalone@latest/babel.min.js" crossorigin="anonymous"></script>

<!-- Where the JS React components are declared. -->
<script type="text/babel" src="js_components.js"></script>
<script defer src="js_components.dart.js"></script>

</body>
</html>
155 changes: 155 additions & 0 deletions example/js_components/js_components.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
@JS()
library js_components;

import 'dart:html';

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

var fooRef;

main() {
aaronlademann-wf marked this conversation as resolved.
Show resolved Hide resolved
setClientConfiguration();

var content = IndexComponent({});

react_dom.render(content, querySelector('#content'));
}

var IndexComponent = react.registerComponent(() => new _IndexComponent());

class _IndexComponent extends react.Component2 {
getInitialState() => {
'open': false,
};

handleClose(_) {
this.setState({
'open': false,
});
}

handleClick(_) {
this.setState({
'open': true,
});
print((simpleRef as SimpleCustomComponent).getFoo());
}

SimpleCustomComponent simpleRef;

render() {
return MuiThemeProvider({
'theme': theme
}, [
react.div({}, [
SimpleCustom({
'foo': 'Foo Prop from dart... IN A JAVASCRIPT COMPONENT!',
'ref': (ref) {
simpleRef = ref;
}
}),
CssBaseline({}),
Dialog({
'open': state['open'],
'onClose': handleClose
}, [
DialogTitle({}, ['Super Secret Password']),
DialogContent({}, [
DialogContentText({}, '1-2-3-4-5'),
]),
DialogActions({}, [
Button({
'color': "primary",
'onClick': handleClose
}, [
'OK',
]),
])
]),
Typography({
'variant': "h4",
'gutterBottom': true
}, [
'Material-UI',
]),
Typography({
'variant': "subtitle1",
'gutterBottom': true
}, [
'example project',
]),
Button({
'variant': "contained",
'color': "secondary",
'onClick': handleClick
}, [
Icon({}, ['fingerprint']),
'Super Secret Password',
]),
])
]);
}
}

/// The JS component class.
///
/// Private since [SimpleCustomComponent] will be used instead.
///
/// Accessible via `SimpleCustomComponent.type`.
@JS()
external ReactClass get _SimpleCustomComponent;

/// A factory for the "_SimpleJsModalContent" JS components class that allows it
/// to be used via Dart code.
///
/// Use this to render instances of the component from within Dart code.
///
/// This converts the Dart props [Map] passed into it in the
/// the same way props are converted for DOM components.
final SimpleCustom = new ReactJsComponentFactoryProxy(_SimpleCustomComponent);

/// JS interop wrapper class for the component,
/// allowing us to interact with component instances
/// made available via refs or [react_dom.render] calls.
///
/// This is optional, as you won't always need to access the component's API.
@JS('_SimpleCustomComponent')
class SimpleCustomComponent {
external String getFoo();
}

/// JS interop wrapper class for Material UI
/// getting us access to the react classes
@JS('material-ui')
class MaterialUI {
external static ReactClass get Button;
external static ReactClass get CssBaseline;
external static ReactClass get Dialog;
external static ReactClass get DialogActions;
external static ReactClass get DialogContent;
external static ReactClass get DialogContentText;
external static ReactClass get DialogTitle;
external static ReactClass get Icon;
external static ReactClass get MuiThemeProvider;
external static ReactClass get Typography;
}

/// JS Interop to get theme config we setup in JS
@JS()
external Map get theme;

// All the Material UI components converted to dart Components
final Button = new ReactJsComponentFactoryProxy(MaterialUI.Button);
final CssBaseline = new ReactJsComponentFactoryProxy(MaterialUI.CssBaseline);
final Dialog = new ReactJsComponentFactoryProxy(MaterialUI.Dialog);
final DialogActions = new ReactJsComponentFactoryProxy(MaterialUI.DialogActions);
final DialogContent = new ReactJsComponentFactoryProxy(MaterialUI.DialogContent);
final DialogContentText = new ReactJsComponentFactoryProxy(MaterialUI.DialogContentText);
final DialogTitle = new ReactJsComponentFactoryProxy(MaterialUI.DialogTitle);
final Icon = new ReactJsComponentFactoryProxy(MaterialUI.Icon);
final MuiThemeProvider = new ReactJsComponentFactoryProxy(MaterialUI.MuiThemeProvider);
final Typography = new ReactJsComponentFactoryProxy(MaterialUI.Typography);
33 changes: 33 additions & 0 deletions example/js_components/js_components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const {createMuiTheme, colors} = window['material-ui'];

const theme = createMuiTheme({
palette: {
primary: {
light: colors.purple[300],
main: colors.purple[500],
dark: colors.purple[700],
},
secondary: {
light: colors.green[300],
main: colors.green[500],
dark: colors.green[700],
},
},
typography: {
useNextVariants: true,
},
});

class _SimpleCustomComponent extends React.Component {
render() {
return (
[
'This is some content to show that custom JS components also work!',
]
);
}

getFoo() {
return this.props.foo;
}
}
37 changes: 21 additions & 16 deletions example/test/context_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';

Expand All @@ -9,23 +10,27 @@ void main() {
setClientConfiguration();

react_dom.render(
contextComponent({}, [
contextConsumerComponent({'key': 'consumerComponent'}),
]),
querySelector('#content'));

react_dom.render(
contextComponent({}, [
contextConsumerComponent({'key': 'consumerComponent'}),
]),
querySelector('#content'));

react_dom.render(
contextComponent({}, [
contextConsumerComponent({
'key': 'consumerComponent'
react.div({}, [
react.h1({}, ['React Legacy Context API']),
legacyContextComponent({}, [
legacyContextConsumerComponent({
'key': 'consumerComponent'
}, [
grandchildLegacyContextConsumerComponent({'key': 'legacyConsumerGrandchildComponent'})
]),
]),
react.h1({'key': 'h1'}, ['React New Context API']),
newContextProviderComponent({
'key': 'newProviderComponent'
}, [
grandchildContextConsumerComponent({'key': 'consumerGrandchildComponent'})
newContextConsumerComponent({
'key': 'newConsumerComponent',
}),
newContextConsumerObservedBitsComponent({
'key': 'newConsumerObservedBitsComponent',
'unstable_observedBits': (1 << 2),
}),
newContextTypeConsumerComponentComponent({'key': 'newContextTypeConsumerComponent'}, []),
]),
]),
querySelector('#content'));
Expand Down
Loading