Skip to content

Instantly share code, notes, and snippets.

@aaronstgeorge-wf
Last active March 5, 2019 18:20
Show Gist options
  • Save aaronstgeorge-wf/f8d2c3e69044156a65f42b3bae860331 to your computer and use it in GitHub Desktop.
Save aaronstgeorge-wf/f8d2c3e69044156a65f42b3bae860331 to your computer and use it in GitHub Desktop.
Typing causes RTE
import 'package:foo/foo.dart';
import 'package:over_react/over_react.dart';
// ignore: uri_has_not_been_generated
part 'bar.over_react.g.dart';
@Factory()
UiFactory<BarProps> Bar =
// ignore: undefined_identifier
_$Bar;
@Props()
class _$BarProps extends UiProps {}
@Component()
class BarComponent extends UiComponent<BarProps> {
@override
render() {
return (Foo()
// With a dynamic type i.e.:
// ..ref = (ref) {
// print(ref.runtimeType); // prints "_$FooComponent"
// ref = ref as FooComponent;
// print(ref.method());
// }
// there isn't a runtime error and the correct thing is printed ("returned
// from method on FooComponent"). With an explicit type a run time exception
// is thrown.
//
// ref is a dynamic public variable on the ReactComponent class, if it is
// set with a function JS will call it with the component when rendered.
..ref = (FooComponent ref) {
print(ref.runtimeType); // prints "NativeJavaScriptObject"
// Cast has no effect on run time behavior, it's here just to show that
// ref is indeed of type FooComponent.
ref = ref as FooComponent;
print(ref.method());
})();
}
}
// This will be removed once the transition to Dart 2 is complete.
class BarProps extends _$BarProps
with
// ignore: mixin_of_non_class, undefined_class
_$BarPropsAccessorsMixin {
// ignore: const_initialized_with_non_constant_value, undefined_class, undefined_identifier
static const PropsMeta meta = _$metaForBarProps;
}
import 'package:over_react/over_react.dart';
// ignore: uri_has_not_been_generated
part 'foo.over_react.g.dart';
@Factory()
UiFactory<FooProps> Foo =
// ignore: undefined_identifier
_$Foo;
@Props()
class _$FooProps extends UiProps {}
@Component()
class FooComponent extends UiComponent<FooProps> {
String method() => 'returned from method on FooComponent';
@override
render() {
return Dom.div()();
}
}
// This will be removed once the transition to Dart 2 is complete.
class FooProps extends _$FooProps
with
// ignore: mixin_of_non_class, undefined_class
_$FooPropsAccessorsMixin {
// ignore: const_initialized_with_non_constant_value, undefined_class, undefined_identifier
static const PropsMeta meta = _$metaForFooProps;
}
<!DOCTYPE html>
<html>
<head>
<title>Foo</title>
</head>
<body>
<div id="react_mount_point"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="main.dart.js"></script>
</body>
</html>
import 'dart:html';
import 'package:foo/bar.dart';
import 'package:over_react/over_react.dart';
import 'package:over_react/react_dom.dart' as react_dom;
main() {
setClientConfiguration();
react_dom.render(Bar()(), querySelector('#react_mount_point'));
}
name: foo
environment:
sdk: '>=1.24.3 <3.0.0'
dependencies:
over_react: ">=1.30.2 <3.0.0"
dev_dependencies:
build_runner: ">=0.6.0 <2.0.0"
build_web_compilers: ">=0.2.0 <2.0.0"
transformers:
- over_react # for dart 1 compatablity
- $dart2js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment