Skip to content

Commit

Permalink
fix(web_workers): support @AngularEntrypoint in web workers
Browse files Browse the repository at this point in the history
And enable transformers on all playground apps

Closes #6013
  • Loading branch information
yjbanov committed Jan 13, 2016
1 parent b0cebdb commit ac85cbb
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 89 deletions.
32 changes: 14 additions & 18 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,24 +906,20 @@ gulp.task('build/pure-packages.dart/standalone', function() {
.pipe(gulp.dest(CONFIG.dest.dart));
});

gulp.task('build/pure-packages.dart/license',
function() {
return gulp.src(['LICENSE'])
.pipe(gulp.dest(path.join(CONFIG.dest.dart, 'angular2_testing')));
})


gulp.task('build/pure-packages.dart/angular2', function() {
var yaml = require('js-yaml');

return gulp.src([
'modules_dart/transform/**/*',
'!modules_dart/transform/**/*.proto',
'!modules_dart/transform/pubspec.yaml',
'!modules_dart/transform/**/packages{,/**}',
])
.pipe(gulp.dest(path.join(CONFIG.dest.dart, 'angular2')));
});
gulp.task('build/pure-packages.dart/license', function() {
return gulp.src(['LICENSE']).pipe(gulp.dest(path.join(CONFIG.dest.dart, 'angular2_testing')));
});


gulp.task('build/pure-packages.dart/angular2', function() {
return gulp.src([
'modules_dart/transform/**/*',
'!modules_dart/transform/**/*.proto',
'!modules_dart/transform/pubspec.yaml',
'!modules_dart/transform/**/packages{,/**}',
])
.pipe(gulp.dest(path.join(CONFIG.dest.dart, 'angular2')));
});

// Builds all Dart packages, but does not compile them
gulp.task('build/packages.dart', function(done) {
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/angular2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ library angular2;
*
* This library does not include `bootstrap`. Import `bootstrap.dart` instead.
*/
export 'package:angular2/core.dart'
hide forwardRef, resolveForwardRef, ForwardRefFn;
export 'package:angular2/core.dart';
export 'package:angular2/common.dart';
export 'package:angular2/instrumentation.dart';
export 'package:angular2/src/core/angular_entrypoint.dart' show AngularEntrypoint;
Expand Down
1 change: 1 addition & 0 deletions modules/angular2/core.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library angular2.core;

export './src/core/angular_entrypoint.dart' show AngularEntrypoint;
export './src/core/metadata.dart';
export './src/core/util.dart';
export 'package:angular2/src/facade/lang.dart' show enableProdMode;
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/platform/worker_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {WORKER_APP_APPLICATION_COMMON} from './worker_app_common';
import {APP_INITIALIZER} from 'angular2/core';
import {MessageBus} from 'angular2/src/web_workers/shared/message_bus';
import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';

// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492)
let _postMessage = {
Expand All @@ -20,6 +21,7 @@ let _postMessage = {

export const WORKER_APP_APPLICATION: Array<any /*Type | Provider | any[]*/> = [
WORKER_APP_APPLICATION_COMMON,
COMPILER_PROVIDERS,
new Provider(MessageBus, {useFactory: createMessageBus, deps: [NgZone]}),
new Provider(APP_INITIALIZER, {useValue: setupWebWorker, multi: true})
];
Expand Down
2 changes: 0 additions & 2 deletions modules/angular2/src/platform/worker_app_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
ServiceMessageBrokerFactory,
ServiceMessageBrokerFactory_
} from 'angular2/src/web_workers/shared/service_message_broker';
import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';
import {Serializer} from "angular2/src/web_workers/shared/serializer";
import {ON_WEB_WORKER} from "angular2/src/web_workers/shared/api";
import {Provider} from 'angular2/src/core/di';
Expand All @@ -37,7 +36,6 @@ export const WORKER_APP_PLATFORM: Array<any /*Type | Provider | any[]*/> =

export const WORKER_APP_APPLICATION_COMMON: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
APPLICATION_COMMON_PROVIDERS,
COMPILER_PROVIDERS,
FORM_PROVIDERS,
Serializer,
new Provider(PLATFORM_PIPES, {useValue: COMMON_PIPES, multi: true}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
inject,
describe,
it,
iit,
expect,
beforeEach,
beforeEachProviders,
SpyObject,
proxy
proxy,
browserDetection
} from 'angular2/testing_internal';
import {createPairedMessageBuses} from '../shared/web_worker_test_util';
import {Serializer, PRIMITIVE} from 'angular2/src/web_workers/shared/serializer';
Expand Down Expand Up @@ -49,19 +51,23 @@ export function main() {
{'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]});
}));

it("should return promises to the worker", inject([Serializer], (serializer) => {
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
expect(arg1).toEqual(PASSED_ARG_1);
return PromiseWrapper.wrap(() => { return RESULT; });
});
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => {
expect(data.type).toEqual("result");
expect(data.id).toEqual(ID);
expect(data.value).toEqual(RESULT);
});
}));
// TODO(pkozlowski): this fails only in Edge with
// "No provider for RenderStore! (Serializer -> RenderStore)"
if (!browserDetection.isEdge) {
it("should return promises to the worker", inject([Serializer], (serializer) => {
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
expect(arg1).toEqual(PASSED_ARG_1);
return PromiseWrapper.wrap(() => { return RESULT; });
});
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => {
expect(data.type).toEqual("result");
expect(data.id).toEqual(ID);
expect(data.value).toEqual(RESULT);
});
}));
}
});
}
2 changes: 2 additions & 0 deletions modules/benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ transformers:
- web/src/static_tree/tree_benchmark.dart
- web/src/tree/tree_benchmark.dart
- $dart2js:
$include: web/src/**
minify: false
commandLineOptions:
- --dump-info
- --trust-type-annotations
- --trust-primitives
- --show-package-warnings
- --fatal-warnings
3 changes: 2 additions & 1 deletion modules/benchmarks_external/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ dependency_overrides:
intl: '^0.12.4' # angular depends on an older version of intl.
transformers:
- angular:
$exclude: "web/e2e_test"
$include: "web/src"
html_files:
- web/src/naive_infinite_scroll/scroll_area.html
- web/src/naive_infinite_scroll/scroll_item.html
- $dart2js:
$include: "web/src"
commandLineOptions:
- --show-package-warnings
73 changes: 45 additions & 28 deletions modules/playground/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ transformers:
- angular2:
platform_directives: 'package:angular2/src/common/directives.dart#CORE_DIRECTIVES'
entry_points:
- web/src/animate/index.dart
- web/src/async/index.dart
- web/src/gestures/index.dart
- web/src/hash_routing/index.dart
- web/src/hello_world/index.dart
- web/src/key_events/index.dart
- web/src/sourcemap/index.dart
- web/src/todo/index.dart
- web/src/order_management/index.dart
- web/src/model_driven_forms/index.dart
- web/src/observable_models/index.dart
- web/src/person_management/index.dart
- web/src/routing/index.dart
- web/src/template_driven_forms/index.dart
- web/src/zippy_component/index.dart
- web/src/relative_assets/index.dart
- web/src/svg/index.dart
- web/src/material/button/index.dart
- web/src/material/checkbox/index.dart
- web/src/material/dialog/index.dart
Expand All @@ -41,25 +33,50 @@ transformers:
- web/src/material/progress-linear/index.dart
- web/src/material/radio/index.dart
- web/src/material/switcher/index.dart
- web/src/model_driven_forms/index.dart
- web/src/observable_models/index.dart
- web/src/order_management/index.dart
- web/src/person_management/index.dart
- web/src/relative_assets/index.dart
- web/src/routing/index.dart
- web/src/sourcemap/index.dart
- web/src/svg/index.dart
- web/src/template_driven_forms/index.dart
- web/src/todo/index.dart
- web/src/web_workers/kitchen_sink/background_index.dart
- web/src/web_workers/kitchen_sink/index.dart
- web/src/web_workers/message_broker/background_index.dart
- web/src/web_workers/message_broker/index.dart
- web/src/web_workers/todo/background_index.dart
- web/src/web_workers/todo/index.dart
- web/src/web_workers/todo/server_index.dart
- web/src/zippy_component/index.dart

# These entrypoints are disabled untl the transformer supports UI bootstrap (issue #3971)
# - web/src/web_workers/message_broker/index.dart
# - web/src/web_workers/kitchen_sink/index.dart
# - web/src/web_workers/todo/index.dart
# - web/src/web_workers/todo/server_index.dart
# - web/src/web_workers/todo/background_index.dart
# - web/src/web_workers/message_broker/background_index.dart
# - web/src/web_workers/kitchen_sink/background_index.dart
#
# This entrypoint is not needed:
# - web/src/material/demo_common.dart
- $dart2js:
$include:
- web/src/**
$exclude:
# web worker code compiled separately; see below
- web/src/web_workers/**
minify: false
commandLineOptions:
- --show-package-warnings
- --trust-type-annotations
- --trust-primitives
- --enable-experimental-mirrors
- --fatal-warnings

# TODO(yjbanov): cannot use --fatal-warnings on web-worker code due to
# dart2js bug https://github.com/dart-lang/sdk/issues/23875
- $dart2js:
$include:
- web/src/web_workers/**
$exclude:
- web/src/web_workers/images/**
- web/src/web_workers/todo/server_index.dart
minify: false
commandLineOptions:
- --show-package-warnings
- --trust-type-annotations
- --trust-primitives
- --enable-experimental-mirrors
# Uncomment to generate summaries from dart2js
# - --dump-info
- --show-package-warnings
- --trust-type-annotations
- --trust-primitives
- --enable-experimental-mirrors
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import "index_common.dart" show HelloCmp;
import "dart:isolate";
import "package:angular2/platform/worker_app.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";

@AngularEntrypoint()
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM, new Provider(RENDER_SEND_PORT, useValue: replyTo)])
.application([WORKER_APP_APPLICATION])
.bootstrap(HelloCmp);
Expand Down
4 changes: 1 addition & 3 deletions modules/playground/src/web_workers/kitchen_sink/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ library angular2.examples.web_workers.kitchen_sink.index;

import "package:angular2/platform/worker_render.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";

@AngularEntrypoint()
main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("background_index.dart"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ library angular2.examples.message_broker.background_index;

import "package:angular2/platform/worker_app.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "index_common.dart" show App;
import "dart:isolate";

@AngularEntrypoint()
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM, new Provider(RENDER_SEND_PORT, useValue: replyTo)])
.application([WORKER_APP_APPLICATION])
.bootstrap(App);
Expand Down
4 changes: 1 addition & 3 deletions modules/playground/src/web_workers/message_broker/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ library angular2.examples.message_broker.index;

import "package:angular2/platform/worker_render.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "dart:html";

@AngularEntrypoint()
main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
const ECHO_CHANNEL = "ECHO";
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("background_index.dart"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import "index_common.dart" show TodoApp;
import "dart:isolate";
import "package:angular2/platform/worker_app.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";

@AngularEntrypoint()
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM, new Provider(RENDER_SEND_PORT, useValue: replyTo)])
.application([WORKER_APP_APPLICATION])
.bootstrap(TodoApp);
Expand Down
4 changes: 1 addition & 3 deletions modules/playground/src/web_workers/todo/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ library angular2.examples.web_workers.todo.index;

import "package:angular2/platform/worker_render.dart";
import "package:angular2/core.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";

@AngularEntrypoint()
main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("background_index.dart"));
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
library angular2.examples.web_workers.todo.index_web_socket;

import "package:angular2/src/core/reflection/reflection_capabilities.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "package:angular2/core.dart";
import "package:angular2/platform/worker_render.dart";
import "package:angular2/src/web_workers/debug_tools/web_socket_message_bus.dart";
import 'dart:html' show WebSocket;

@AngularEntrypoint()
main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
var webSocket = new WebSocket("ws://127.0.0.1:1337/ws");
webSocket.onOpen.listen((e) {
var bus = new WebSocketMessageBus.fromWebSocket(webSocket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ const _VIEWS = const [

const _ENTRYPOINTS = const [
const ClassDescriptor('AngularEntrypoint', 'package:angular2/angular2.dart'),
const ClassDescriptor('AngularEntrypoint', 'package:angular2/core.dart'),
const ClassDescriptor('AngularEntrypoint', 'package:angular2/bootstrap.dart'),
const ClassDescriptor(
'AngularEntrypoint', 'package:angular2/bootstrap_static.dart'),
const ClassDescriptor(
'AngularEntrypoint', 'package:angular2/platform/browser.dart'),
const ClassDescriptor(
'AngularEntrypoint', 'package:angular2/platform/worker_app.dart'),
const ClassDescriptor(
'AngularEntrypoint', 'package:angular2/platform/browser_static.dart'),
const ClassDescriptor(
Expand Down
Loading

0 comments on commit ac85cbb

Please sign in to comment.