angular / angular/angular-cli

Worklet support

Đang mở
#29,130 5 bình luận 14 reaction 0 người được giao Xem trên GitHub
angular/build:application area: @angular/build feature feature: insufficient votes
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
14 giờ 23 phút
Pull request đã merge (30 ngày)
162

Mô tả

### 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);
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng việc đọc hỗ trợ web-worker hiện có của compiler và so sánh với Worklet API được mô tả trong issue. Công việc hoàn tất khi Angular cung cấp hỗ trợ biên dịch và bundling TypeScript tương đương cho worklet, kèm theo độ bao phủ cho luồng tải được yêu cầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
build-system
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.