Skip to content

Commit 93ddec0

Browse files
committed
Unify workers and wasm
1 parent 6d4a27d commit 93ddec0

File tree

16 files changed

+202
-188
lines changed

16 files changed

+202
-188
lines changed

@types/core/di/ng-module.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,24 @@ export class NgModule {
155155
ctlFn: import("../../interface.ts").Injectable<any>,
156156
): NgModule;
157157
/**
158+
* Register a named worker that will be instantiated via $provide.
159+
*
158160
* @param {string} name
159161
* @param {string} src
160162
* @returns {NgModule}
161163
*/
162164
wasm(name: string, src: string): NgModule;
165+
/**
166+
* Register a named worker that will be instantiated via $provide.
167+
*
168+
* @param {string} name
169+
* @param {string | URL} scriptPath
170+
* @param {ng.WorkerConfig} [config]
171+
* @returns {NgModule}
172+
*/
173+
worker(
174+
name: string,
175+
scriptPath: string | URL,
176+
config?: ng.WorkerConfig,
177+
): NgModule;
163178
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export interface WorkerConnection {
99
post(data: any): void;
1010
terminate(): void;
1111
restart(): void;
12+
config: WorkerConfig;
1213
}
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
/**
2-
* ngWorker directive factory
32
* Usage: <div ng-worker="workerName" data-params="{{ expression }}" data-on-result="callback($result)"></div>
3+
*
4+
* @param {ng.ParseService} $parse
5+
* @param {ng.LogService} $log
6+
* @returns {ng.Directive}
47
*/
58
export function ngWorkerDirective(
6-
$worker: any,
7-
$parse: any,
8-
$log: any,
9-
): {
10-
restrict: string;
11-
link(scope: any, element: any, attrs: any): void;
12-
};
9+
$parse: ng.ParseService,
10+
$log: ng.LogService,
11+
): ng.Directive;
1312
export namespace ngWorkerDirective {
1413
let $inject: string[];
1514
}
15+
/**
16+
* Creates a managed Web Worker connection.
17+
*
18+
* @param {string | URL} scriptPath
19+
* @param {ng.WorkerConfig} [config]
20+
* @returns {ng.WorkerConnection}
21+
*/
22+
export function createWorkerConnection(
23+
scriptPath: string | URL,
24+
config?: ng.WorkerConfig,
25+
): ng.WorkerConnection;

@types/namespace.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
import {
6060
WorkerConnection as TWorkerConnection,
6161
WorkerConfig as TWorkerConfig,
62-
} from "./services/worker/interface.ts";
62+
} from "./directive/worker/interface.ts";
6363
import { Provider as TProvideService } from "./interface.ts";
6464
import { Location as TLocationService } from "./services/location/location.js";
6565
import { AnimateService as TAnimateService } from "./animations/interface.ts";

@types/services/worker/worker.d.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

@types/shared/utils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export function wait(t?: number): Promise<void>;
583583
*/
584584
export function startsWith(str: string, search: string): boolean;
585585
/**
586-
* Loads and instantiates a WebAssembly module with proper error handling.
586+
* Loads and instantiates a WebAssembly module
587587
*
588588
* @param {string} src - URL to the wasm file
589589
* @returns {Promise<Object>} - Resolves to wasm exports

docs/static/typedoc/interfaces/Directive.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/core/di/injector.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export function createInjector(modulesToLoad, strictDi = false) {
3939
service: supportObject(service),
4040
value: supportObject(value),
4141
constant: supportObject(constant),
42-
wasm: supportObject(wasm),
4342
decorator,
4443
},
4544
};
@@ -155,17 +154,6 @@ export function createInjector(modulesToLoad, strictDi = false) {
155154
protoInstanceInjector.cache[name] = value;
156155
}
157156

158-
/**
159-
* Register a wasm module (available during config).
160-
* @param {string} name
161-
* @param {string} value
162-
* @returns {void}
163-
*/
164-
function wasm(name, value) {
165-
providerInjector.cache[name] = value;
166-
protoInstanceInjector.cache[name] = value;
167-
}
168-
169157
/**
170158
* Register a decorator function to modify or replace an existing service.
171159
* @param name - The name of the service to decorate.

src/core/di/ng-module.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { $injectTokens as $t } from "../../injection-tokens.js";
2+
import { createWorkerConnection } from "../../directive/worker/worker.js";
23
import {
34
isFunction,
45
isString,
@@ -235,15 +236,49 @@ export class NgModule {
235236
}
236237

237238
/**
239+
* Register a named worker that will be instantiated via $provide.
240+
*
238241
* @param {string} name
239242
* @param {string} src
240243
* @returns {NgModule}
241244
*/
242245
wasm(name, src) {
243246
this.invokeQueue.push([
244247
$t.$provide,
245-
"wasm",
246-
[name, (() => instantiateWasm(src))()],
248+
"provider",
249+
[
250+
name,
251+
function () {
252+
this.$get = function () {
253+
return instantiateWasm(src);
254+
};
255+
},
256+
],
257+
]);
258+
259+
return this;
260+
}
261+
262+
/**
263+
* Register a named worker that will be instantiated via $provide.
264+
*
265+
* @param {string} name
266+
* @param {string | URL} scriptPath
267+
* @param {ng.WorkerConfig} [config]
268+
* @returns {NgModule}
269+
*/
270+
worker(name, scriptPath, config = {}) {
271+
this.invokeQueue.push([
272+
$t.$provide,
273+
"provider",
274+
[
275+
name,
276+
function () {
277+
this.$get = function () {
278+
return createWorkerConnection(scriptPath, config);
279+
};
280+
},
281+
],
247282
]);
248283
return this;
249284
}

src/directive/http/http.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
toKeyValue,
88
wait,
99
} from "../../shared/utils.js";
10-
import { createElementFromHTML } from "../../shared/dom.js";
1110

1211
/**
1312
* @param {"get" | "delete" | "post" | "put"} method - HTTP method applied to request

0 commit comments

Comments
 (0)