-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed Preact thread utilities to be class-based instead of being a …
…collection of utility functions (#818)
- Loading branch information
Showing
10 changed files
with
323 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
'@quilted/threads': major | ||
'@quilted/events': patch | ||
'@quilted/quilt': patch | ||
--- | ||
|
||
Changed Preact thread utilities to be class-based instead of being a collection of utility functions. | ||
|
||
Previously, you used `createThreadSignal()` to serialize a Preact signal to pass over a thread, and `acceptThreadSignal()` to turn it into a "live" signal. With the new API, you will do the same steps, but with `ThreadSignal.serialize()` and `new ThreadSignal()`: | ||
|
||
```js | ||
import {signal, computed} from '@preact/signals-core'; | ||
import {ThreadWebWorker, ThreadSignal} from '@quilted/threads'; | ||
|
||
// Old API: | ||
const result = signal(32); | ||
const serializedSignal = createThreadSignal(result); | ||
await thread.imports.calculateResult(serializedSignal); | ||
|
||
// New API: | ||
const result = signal(32); | ||
const serializedSignal = ThreadSignal.serialize(result); | ||
await thread.imports.calculateResult(serializedSignal); | ||
|
||
// In the target thread: | ||
|
||
// Old API: | ||
function calculateResult(resultThreadSignal) { | ||
const result = acceptThreadSignal(resultThreadSignal); | ||
const computedSignal = computed(() => `Result from thread: ${result.value}`); | ||
// ... | ||
} | ||
|
||
// New API: | ||
function calculateResult(resultThreadSignal) { | ||
const result = new ThreadSignal(resultThreadSignal); | ||
const computedSignal = computed(() => `Result from thread: ${result.value}`); | ||
// ... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.