Skip to content

Commit

Permalink
Merge pull request #95 from cloudnc/fix/readme-legacy-webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-cloudnc authored Feb 14, 2022
2 parents 49e16aa + 11b7c1d commit fbf23a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,33 @@ yarn add observable-webworker

💡 Take note! The webworker construction syntax differs for different version of webpack:

#### Webpack < 5
#### Webpack < 5 (deprecated)

```ts
// src/readme/hello.ts
// src/readme/hello-legacy-webpack.ts

import { fromWorker } from 'observable-webworker';
import { of } from 'rxjs';

const input$ = of('Hello from main thread');

fromWorker<string, string>(
() => new Worker(new URL('./hello.worker', import.meta.url), { type: 'module' }),
input$,
).subscribe(message => {
fromWorker<string, string>(() => new Worker('./hello.worker', { type: 'module' }), input$).subscribe(message => {
console.log(message); // Outputs 'Hello from webworker'
});

```
#### Webpack 5

```ts
// src/readme/hello-webpack-5.ts#L2-L12
// src/readme/hello.ts#L2-L12

import { fromWorker } from 'observable-webworker';
import { of } from 'rxjs';

const input$ = of('Hello from main thread');

fromWorker<string, string>(
() => new Worker(new URL('./app.worker', import.meta.url), { type: 'module' }),
() => new Worker(new URL('./hello.worker', import.meta.url), { type: 'module' }),
input$,
).subscribe(message => {
console.log(message); // Outputs 'Hello from webworker'
Expand Down
8 changes: 8 additions & 0 deletions src/readme/hello-legacy-webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { fromWorker } from 'observable-webworker';
import { of } from 'rxjs';

const input$ = of('Hello from main thread');

fromWorker<string, string>(() => new Worker('./hello.worker', { type: 'module' }), input$).subscribe(message => {
console.log(message); // Outputs 'Hello from webworker'
});
12 changes: 0 additions & 12 deletions src/readme/hello-webpack-5.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/readme/hello.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck - @todo remove typechecking prevention once the typescript config supports it
import { fromWorker } from 'observable-webworker';
import { of } from 'rxjs';

Expand Down

0 comments on commit fbf23a2

Please sign in to comment.