Skip to content

AF-2971 Dart 2 compatibility #137

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

Merged
merged 7 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
language: dart
dart:
- 1.24.3
- stable
sudo: required
addons:
chrome: stable
cache:
directories:
- $HOME/.pub-cache
script:
- pub get --packages-dir
- pub run dart_dev format --check
- pub get
- pub run dart_dev dart2-only -- format --check
- pub run dart_dev analyze
- pub run dart_dev test
- pub run dart_dev coverage --no-html
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov
- pub run dart_dev dart1-only -- coverage --no-html && bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov

43 changes: 3 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
FROM google/dart:1.24.3 as build

Copy link
Member Author

Choose a reason for hiding this comment

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

Just let Travis CI run all the tests.

RUN apt-get update -qq
RUN apt-get update && apt-get install -y \
build-essential \
wget \
&& rm -rf /var/lib/apt/lists/*

# install chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list && \
apt-get -qq update && apt-get install -y google-chrome-stable && \
mv /usr/bin/google-chrome-stable /usr/bin/google-chrome && \
sed -i --follow-symlinks -e 's/\"\$HERE\/chrome\"/\"\$HERE\/chrome\" --no-sandbox/g' /usr/bin/google-chrome && \
google-chrome --version


WORKDIR /build

# setup ssh
ARG GIT_SSH_KEY
ARG KNOWN_HOSTS_CONTENT
RUN mkdir /root/.ssh/ && \
echo "$KNOWN_HOSTS_CONTENT" > "/root/.ssh/known_hosts" && \
chmod 700 /root/.ssh/ && \
umask 0077 && echo "$GIT_SSH_KEY" >/root/.ssh/id_rsa && \
eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa

# grab source
COPY . /build/

# deps / test / sanity check / build
ENV DART_FLAGS="--checked"
ARG BUILD_ID
ARG GIT_COMMIT
ARG GIT_TAG
ARG GIT_BRANCH
ARG GIT_MERGE_HEAD
ARG GIT_MERGE_BRANCH
RUN pub get --packages-dir && \
pub run dart_dev test --pub-serve --web-compiler=dartdevc -p chrome -p vm
WORKDIR /build/
ADD pubspec.* /build/
RUN pub get
ARG BUILD_ARTIFACTS_BUILD=/build/pubspec.lock
FROM scratch
4 changes: 2 additions & 2 deletions example/panel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div id="panel-container"></div>

<script src="packages/react/react_with_react_dom_prod.js"></script>
<script type="application/dart" src="panel_app.dart"></script>
<script src="packages/browser/dart.js"></script>
<script defer src="panel_app.dart.js"></script>

</body>
</html>
2 changes: 1 addition & 1 deletion example/panel/modules/data_load_async_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DataLoadAsyncStore extends Store {
}

// ignore: non_constant_identifier_names
Object DataLoadAsyncComponent =
var DataLoadAsyncComponent =
react.registerComponent(() => new _DataLoadAsyncComponent());

class _DataLoadAsyncComponent
Expand Down
2 changes: 1 addition & 1 deletion example/panel/modules/flux_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FluxStore extends Store {
}

// ignore: non_constant_identifier_names
Object MyFluxComponent = react.registerComponent(() => new _MyFluxComponent());
var MyFluxComponent = react.registerComponent(() => new _MyFluxComponent());

class _MyFluxComponent extends FluxComponent<FluxActions, FluxStore> {
@override
Expand Down
2 changes: 1 addition & 1 deletion example/panel/modules/hierarchy_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class HierarchyStore extends Store {
}

// ignore: non_constant_identifier_names
Object HierarchyComponent =
var HierarchyComponent =
react.registerComponent(() => new _HierarchyComponent());

class _HierarchyComponent
Expand Down
4 changes: 2 additions & 2 deletions example/panel/modules/panel_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class PanelStore extends Store {
PanelModule _parentModule;

PanelStore(this._actions, this._parentModule) {
triggerOnAction(_actions.changeToPanel, _changeToPanel);
triggerOnActionV2(_actions.changeToPanel, _changeToPanel);
}

bool get isRenderable => _isRenderable;
Expand Down Expand Up @@ -138,7 +138,7 @@ class PanelStore extends Store {
}

// ignore: non_constant_identifier_names
Object PanelComponent = react.registerComponent(() => new _PanelComponent());
var PanelComponent = react.registerComponent(() => new _PanelComponent());

class _PanelComponent extends FluxComponent<PanelActions, PanelStore> {
@override
Expand Down
2 changes: 1 addition & 1 deletion example/panel/modules/reject_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class RejectStore extends Store {
}

// ignore: non_constant_identifier_names
Object RejectComponent = react.registerComponent(() => new _RejectComponent());
var RejectComponent = react.registerComponent(() => new _RejectComponent());

class _RejectComponent extends FluxComponent<RejectActions, RejectStore> {
@override
Expand Down
3 changes: 1 addition & 2 deletions example/panel/modules/sample_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class SampleSpan implements Span {
this.references,
DateTime startTime,
Map<String, dynamic> tags,
})
: this.startTime = startTime ?? new DateTime.now(),
}) : this.startTime = startTime ?? new DateTime.now(),
Copy link
Member Author

Choose a reason for hiding this comment

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

dart 2 formatter change

this.tags = tags ?? {} {
if (childOf != null) {
references.add(new Reference.childOf(childOf));
Expand Down
4 changes: 2 additions & 2 deletions example/random_color/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h4>Render the module UI here:</h4>
</div>

<script src="packages/react/react_with_react_dom_prod.js"></script>
<script type="application/dart" src="random_color.dart"></script>
<script src="packages/browser/dart.js"></script>
<script defer src="random_color.dart.js"></script>

</body>
</html>
2 changes: 1 addition & 1 deletion example/random_color/random_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class RandomColorStore extends Store {
}

// ignore: non_constant_identifier_names
Object RandomColorComponent =
var RandomColorComponent =
react.registerComponent(() => new _RandomColorComponent());

class _RandomColorComponent
Expand Down
4 changes: 2 additions & 2 deletions lib/src/lifecycle_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
]);
}

Future pendingTransition;
Future<Null> pendingTransition;
Copy link
Member Author

Choose a reason for hiding this comment

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

changed to match the type signature of _suspend

Copy link
Member Author

Choose a reason for hiding this comment

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

this is internal and not a public api change

if (_transition != null && !_transition.isCompleted) {
pendingTransition = _transition.future.then((_) {
_activeSpan = _startTransitionSpan('suspend');
Expand Down Expand Up @@ -661,7 +661,7 @@ abstract class LifecycleModule extends SimpleModule with Disposable {
allowedStates: [LifecycleState.suspended, LifecycleState.suspending]);
}

Future pendingTransition;
Future<Null> pendingTransition;
Copy link
Member Author

Choose a reason for hiding this comment

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

changed to match the type signature of _resume

Copy link
Member Author

Choose a reason for hiding this comment

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

also internal only. no public api change.

if (_transition != null && !_transition.isCompleted) {
pendingTransition = _transition.future.then((_) {
_activeSpan = _startTransitionSpan('resume');
Expand Down
25 changes: 13 additions & 12 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ authors:
- Trent Grover <[email protected]>
homepage: https://github.com/Workiva/w_module

environment:
sdk: '>=1.24.3 <3.0.0'

dependencies:
logging: ^0.11.0
meta: ^1.0.0
Expand All @@ -18,18 +21,16 @@ dependencies:
w_common: ^1.9.0

dev_dependencies:
browser: ^0.10.0+2
coverage: ^0.7.3
dart_dev: ^1.8.0
dart_style: ^1.0.7
dartdoc: ">=0.13.0 <0.16.0"
mockito: ^1.0.1
react: ^3.0.0
test: ^0.12.0
w_flux: '>=1.0.0 <3.0.0'

environment:
sdk: '>=1.9.0 <2.0.0'
build_runner: ">=0.6.0 <1.0.0"
build_test: ">=0.9.0 <1.0.0"
build_web_compilers: ">=0.2.0 <1.0.0"
coverage: ">=0.10.0 <0.13.0"
dart_dev: ^2.0.0
dart_style: ^1.0.9
mockito: ">=2.2.2 <4.0.0"
react: ^4.4.2
test: ">=0.12.30 <2.0.0"
w_flux: ">=1.0.0 <3.0.0"

transformers:
- test/pub_serve:
Expand Down
5 changes: 4 additions & 1 deletion test/lifecycle_module_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class TestLifecycleModule extends LifecycleModule {
@override
@protected
Future<Null> onWillUnloadChildModule(LifecycleModule module) async {
await new Future.value(null);
Copy link
Member Author

Choose a reason for hiding this comment

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

This spot is a little more concerning because this may mean that it's possible for other consumers that are overriding one of these lifecycle methods may get a change in how lifecycle events are ordered due to sync-async. I think we can go ahead with this PR as is, but be aware that there may be a recommended migration step of putting a line like this in each overriden module lifecycle method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Without this await here .. the order that events are added to the tracking list of events is different than what the tests expect the order to be. This looks like:

00:05 +216 -1: [VM] test/lifecycle_module_test.dart: LifecycleModule with globalTracer with children unload should wait for in-progress child module loads  [E]
  Expected: [
              'onWillLoadChildModule',
              'willLoadChildModule',
              'onShouldUnload',
              'willUnload',
              'onDidLoadChildModule',
              'didLoadChildModule',
              'onWillUnloadChildModule',
              'willUnloadChildModule',
              'onDidUnloadChildModule',
              'didUnloadChildModule',
              'onUnload',
              'didUnload',
              'onDispose'
            ]
    Actual: [
              'onWillLoadChildModule',
              'willLoadChildModule',
              'onShouldUnload',
              'willUnload',
              'onDidLoadChildModule',
              'onWillUnloadChildModule',
              'didLoadChildModule',
              'willUnloadChildModule',
              'onDidUnloadChildModule',
              'didUnloadChildModule',
              'onUnload',
              'didUnload',
              'onDispose'
            ]
     Which: was 'onWillUnloadChildModule' instead of 'didLoadChildModule' at location [5]

  package:test                             expect
  test/lifecycle_module_test.dart 2236:11  runTests.<fn>.<fn>.<fn>.<fn>

if (onWillUnloadChildModuleError != null) {
throw onWillUnloadChildModuleError;
}
Expand Down Expand Up @@ -280,6 +281,8 @@ void expectInLifecycleState(LifecycleModule module, LifecycleState state) {
}

Future<Null> gotoState(LifecycleModule module, LifecycleState state) async {
// wait for next event loop. fixes sync-async in Dart 2
await new Future.value(null);
Copy link
Member Author

Choose a reason for hiding this comment

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

@Workiva/app-frameworks want to take a look at these closely to determine if we're going to have a sync-async problem with lifecycle module or if it's just the tests and mocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

well, goto state is only used internally in tests, so I'm not too concerned about this one.

if (state == LifecycleState.instantiated) {
return;
}
Expand All @@ -288,7 +291,7 @@ Future<Null> gotoState(LifecycleModule module, LifecycleState state) async {
if (state == LifecycleState.loading) {
return;
}
await future;
await future; // Dart 2 would have run synchronously up until this await
if (state == LifecycleState.loaded) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions test/test_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class TestSpan implements Span {
List<Reference> references,
DateTime startTime,
Map<String, dynamic> tags,
})
: this.startTime = startTime ?? new DateTime.now(),
}) : this.startTime = startTime ?? new DateTime.now(),
this.tags = tags ?? {},
this.references = references ?? [] {
if (childOf != null) {
Expand Down