Worklet support

未關閉
#29,130 5 則留言 14 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
angular, typescript
領域
build-system

研究方向

首先閱讀編譯器現有的 web-worker 支援,並將其與 issue 中描述的 Worklet API 進行比較。當 Angular 為 worklet 提供等效的 TypeScript 編譯和打包支援,並涵蓋所要求的載入流程時,工作就完成了。

由索引模型根據 Issue 內容生成。

描述

angular/build:application area: @angular/build feature feature: insufficient votes
Which @angular/* package(s) are relevant/related to the feature request?

compiler

Description

The worklets are light weighted version of web workers. Currently Angular supports web workers, but not worklets, this makes us unable to make use of Angular's Typescript and bundling support when writing a worklet (i.e. we have to write the worklet in pure Javasctript, or deal with compiling and bundling ourselves).

Proposed solution

Support worklet like web workers.

Alternatives considered

For now we have come to a hacky workaround:

  1. Write the worklet as if it's a web worker. This is perfecly supported by Angular. Now the problem is, to load the compiled worker script, we don't have a trivial way to get its URL.

  2. Wrap the worker code like this:

if (typeof self !== "undefined") {
  postMessage(self.location.href);
} else {
  // do the worklet thing
}

When self is not undefined, we know this script is loaded as a webworker (in a worklet context it would be undefined). In this case, send the script's location by postMessage.

  1. When trying to load the worklet, first load it as a web worker, wait for it to report the location, then terminate the worker and use the location to load the worklet.

E.g. load an audio worklet:

// probe worker url
const worker = new Worker(
  new URL("path/to/the/worker", import.meta.url),
);

const url = await new Promise<string>((resolve, reject) => {
  worker.onmessage = (e) => {
    resolve(e.data);
    worker.terminate();
  };

  worker.onmessageerror = reject;
});

await audioContext.audioWorklet.addModule(url);
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
16 小時 35 分鐘
30 天內合併 PR
176

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。