Worklet support

Abierto
#29,130 5 comentarios 14 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
angular, typescript
Área
build-system

Línea de trabajo

Empieza leyendo el soporte existente de web-worker del compilador y comparándolo con la Worklet API descrita en el issue. El trabajo estará terminado cuando Angular proporcione soporte equivalente de compilación y bundling de TypeScript para worklets, con cobertura para el flujo de carga solicitado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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);
Lenguaje dominante
TypeScript
Estrellas
27k
Forks
11.8k
Merge medio
16 h 35 min
PR fusionados (30 d)
176

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de angular/angular-cli

Todos los issues de angular/angular-cli

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.