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

fix(web_workers): support @AngularEntrypoint in web workers #6013

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 14 additions & 18 deletions gulpfile.js
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
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
@@ -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
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
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
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
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
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
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
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
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"));
}
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
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
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
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"));
}
@@ -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
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