This repository was archived by the owner on May 29, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ npm i @ng-web-apis/workers
2828
2929## How it use
3030
31- You can create worker and use it in a template with ` AsyncPipe ` :
31+ Create a worker and use it in a template with ` AsyncPipe ` :
3232
3333``` typescript
3434import {WebWorker } from ' @ng-web-apis/workers' ;
@@ -39,7 +39,8 @@ function compute(data: number): number {
3939
4040@Component ({
4141 template: `
42- Computed Result: {{ worker | async }}
42+ Computed Result:
43+ <ng-container *ngIf="worker | async as event">{{ event.data }}</ng-container>
4344 <form (ngSubmit)="worker.postMessage(input.value)">
4445 <input #input />
4546 <button type="submit">Send to worker</button>
@@ -51,6 +52,30 @@ class SomeComponent {
5152}
5253```
5354
55+ To get data from the worker event, use the toData operator
56+
57+ ``` typescript
58+ import {toData , WebWorker } from ' @ng-web-apis/workers' ;
59+
60+ function compute(data : number ): number {
61+ return data ** 2 ;
62+ }
63+
64+ @Component ({
65+ template: `
66+ Computed Result: {{ workerData$ | async }}
67+ <form (ngSubmit)="worker.postMessage(input.value)">
68+ <input #input />
69+ <button type="submit">Send to worker</button>
70+ </form>
71+ ` ,
72+ })
73+ class SomeComponent {
74+ readonly worker = WebWorker .fromFunction <number , number >(compute );
75+ readonly workerData$ = this .worker .pipe (toData ());
76+ }
77+ ```
78+
5479It's the same with ` WorkerPipe ` only:
5580
5681``` typescript
You can’t perform that action at this time.
0 commit comments