Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 29, 2023. It is now read-only.
/workersPublic archive

A library for comfortable use of Web Workers API in Angular

License

NotificationsYou must be signed in to change notification settings

ng-web-apis/workers



Attention! This repository is archived and the library has been moved totinkoff/ng-web-apis monorepository



ng-web-apis logo Web Workers API for Angular

Part ofWeb APIs for Angular

npm versionnpm bundle sizeBuild and ReleaseCoveralls githubangular-open-source-starter

This is a library for comfortable use ofWeb Workers APIwith Angular.

Install

If you do not have@ng-web-apis/common:

npm i @ng-web-apis/common

Now install the package:

npm i @ng-web-apis/workers

How it use

Create a worker and use it in a template withAsyncPipe:

import{WebWorker}from'@ng-web-apis/workers';functioncompute(data:number):number{returndata**2;}@Component({template:`        Computed Result:        <ng-container *ngIf="worker | async as event">{{ event.data }}</ng-container>        <form (ngSubmit)="worker.postMessage(input.value)">            <input #input />            <button type="submit">Send to worker</button>        </form>    `,})classSomeComponent{readonlyworker=WebWorker.fromFunction<number,number>(compute);}

To get data from the worker event, use the toData operator

import{toData,WebWorker}from'@ng-web-apis/workers';functioncompute(data:number):number{returndata**2;}@Component({template:`        Computed Result: {{ workerData$ | async }}        <form (ngSubmit)="worker.postMessage(input.value)">            <input #input />            <button type="submit">Send to worker</button>        </form>    `,})classSomeComponent{readonlyworker=WebWorker.fromFunction<number,number>(compute);readonlyworkerData$=this.worker.pipe(toData());}

It's the same withWorkerPipe only:

import{WorkerModule}from'@ng-web-apis/workers';import{NgModule}from'@angular/core';@NgModule({imports:[WorkerModule],declarations:[SomeComponent],})classSomeModule{}
import{WorkerExecutor,WebWorker}from'@ng-web-apis/workers';import{FormControl}from'@angular/forms';@Component({template:`        Computed Result: {{ value | waWorker: changeData | async }}        <input [(ngModel)]="value" />    `,})classSomeComponent{value:string;changeData(data:string):string{return`${data} (changed)`;}}

See also

OtherWeb APIs for Angular by@ng-web-apis

Open-source

Do you also want to open-source something, but hate the collateral work?Check out thisAngular Open-source Library Starterwe’ve created for our projects. It got you covered on continuous integration,pre-commit checks, linting, versioning + changelog, code coverage and all that jazz.

About

A library for comfortable use of Web Workers API in Angular

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors3

    •  
    •  
    •  

    [8]ページ先頭

    ©2009-2025 Movatter.jp