Worklet support
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 14 小时 23 分钟
- 30 天内合并 PR
- 162
描述
### Which @angular/* package(s) are relevant/related to the feature request?
compiler
### Description
The [worklets](https://developer.mozilla.org/en-US/docs/Web/API/Worklet) 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:
```js
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`.
3. 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:
```typescript
// probe worker url
const worker = new Worker(
new URL("path/to/the/worker", import.meta.url),
);
const url = await new Promise((resolve, reject) => {
worker.onmessage = (e) => {
resolve(e.data);
worker.terminate();
};
worker.onmessageerror = reject;
});
await audioContext.audioWorklet.addModule(url);
```
贡献指南
调研方向
首先阅读编译器现有的 web-worker 支持,并将其与 issue 中描述的 Worklet API 进行比较。当 Angular 为 worklet 提供等效的 TypeScript 编译和打包支持,并覆盖所请求的加载流程时,工作就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, typescript
- 领域
- build-system
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100