@isoloop/preact 0.1.0-next.11 → 0.1.0-next.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/package.json +14 -5
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @isoloop/preact
|
|
2
|
+
|
|
3
|
+
Preact for [Isoloop](https://isoloop.dev): write an isolate as a Preact component, rendered in its worker and drawn on the page.
|
|
4
|
+
|
|
5
|
+
## What you get
|
|
6
|
+
|
|
7
|
+
- **Your components in a worker:** `defineIsolate(Component)` turns a Preact 10 or 11 component into an isolate.
|
|
8
|
+
- **Topics as state:** `useTopic` follows a topic's latest value, read again after a restart with `from: 'earliest'`, and `usePublish` writes to a topic.
|
|
9
|
+
- **The page through hooks:** `useHost` to measure, focus, scroll, navigate and get a canvas, and `useRoute` for the current location.
|
|
10
|
+
- **Portals:** `usePortalRoot` gives modals, tooltips and menus a place inside the isolate.
|
|
11
|
+
- **Errors reach the supervisor:** a render error restarts that isolate, and in a pool only that member.
|
|
12
|
+
- **Request and reply** (experimental): `useRequest`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @isoloop/preact@next @isoloop/runtime@next preact
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { defineIsolate, usePublish, useTopic } from '@isoloop/preact';
|
|
24
|
+
import { count } from './topics'; // a topic from your contracts
|
|
25
|
+
|
|
26
|
+
function Counter() {
|
|
27
|
+
const n = useTopic(count, { from: 'earliest' }) ?? 0;
|
|
28
|
+
const publish = usePublish(count);
|
|
29
|
+
return <button onClick={() => void publish(n + 1)}>Count: {n}</button>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default defineIsolate(Counter);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Learn more
|
|
36
|
+
|
|
37
|
+
- [Preact isolates](https://isoloop.dev/docs/isolates/#preact) and [the hooks](https://isoloop.dev/docs/isolates/#the-hooks)
|
|
38
|
+
- [What Isoloop can't hide](https://isoloop.dev/docs/limits/)
|
|
39
|
+
- [API reference](https://isoloop.dev/docs/api/preact/)
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,12 @@ type UseTopicOptions = {
|
|
|
58
58
|
* The latest value on `topic`. It subscribes on mount and unsubscribes on unmount;
|
|
59
59
|
* a different `topic` or `from` subscribes again.
|
|
60
60
|
*
|
|
61
|
+
* An isolate has one subscription per topic. A second `useTopic` on the same topic, in
|
|
62
|
+
* another component or another call in the same one, replaces the first with no error: only
|
|
63
|
+
* the last one subscribed gets records, and the first stops updating. When the last one
|
|
64
|
+
* unmounts, the topic has no subscription, and the first doesn't get it back. Call
|
|
65
|
+
* `useTopic` once per topic, and pass the value down as props or share it through context.
|
|
66
|
+
*
|
|
61
67
|
* @param topic - The topic to read. The isolate needs a subscribe grant for it.
|
|
62
68
|
* @param opts - Where reading starts ({@link UseTopicOptions}).
|
|
63
69
|
* @returns The latest value, or `undefined` until one arrives. A bus restart that lost a
|
package/dist/index.js
CHANGED
|
@@ -129,6 +129,12 @@ function defineIsolate(Component) {
|
|
|
129
129
|
* The latest value on `topic`. It subscribes on mount and unsubscribes on unmount;
|
|
130
130
|
* a different `topic` or `from` subscribes again.
|
|
131
131
|
*
|
|
132
|
+
* An isolate has one subscription per topic. A second `useTopic` on the same topic, in
|
|
133
|
+
* another component or another call in the same one, replaces the first with no error: only
|
|
134
|
+
* the last one subscribed gets records, and the first stops updating. When the last one
|
|
135
|
+
* unmounts, the topic has no subscription, and the first doesn't get it back. Call
|
|
136
|
+
* `useTopic` once per topic, and pass the value down as props or share it through context.
|
|
137
|
+
*
|
|
132
138
|
* @param topic - The topic to read. The isolate needs a subscribe grant for it.
|
|
133
139
|
* @param opts - Where reading starts ({@link UseTopicOptions}).
|
|
134
140
|
* @returns The latest value, or `undefined` until one arrives. A bus restart that lost a
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isoloop/preact",
|
|
3
|
-
"version": "0.1.0-next.
|
|
4
|
-
"description": "Preact
|
|
3
|
+
"version": "0.1.0-next.12",
|
|
4
|
+
"description": "Preact for Isoloop: run a component as an isolate in a worker, with hooks for the message bus and the host.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"isoloop",
|
|
7
|
+
"web-workers",
|
|
8
|
+
"event-loop",
|
|
9
|
+
"isolation",
|
|
10
|
+
"preact",
|
|
11
|
+
"microfrontends"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://isoloop.dev/docs/api/preact/",
|
|
5
14
|
"license": "MIT",
|
|
6
15
|
"type": "module",
|
|
7
16
|
"sideEffects": false,
|
|
@@ -23,11 +32,11 @@
|
|
|
23
32
|
"preact": "^10 || ^11"
|
|
24
33
|
},
|
|
25
34
|
"dependencies": {
|
|
26
|
-
"@isoloop/protocol": "0.1.0-next.
|
|
27
|
-
"@isoloop/runtime": "0.1.0-next.
|
|
35
|
+
"@isoloop/protocol": "0.1.0-next.12",
|
|
36
|
+
"@isoloop/runtime": "0.1.0-next.12"
|
|
28
37
|
},
|
|
29
38
|
"devDependencies": {
|
|
30
|
-
"@isoloop/dom": "0.1.0-next.
|
|
39
|
+
"@isoloop/dom": "0.1.0-next.12",
|
|
31
40
|
"preact10": "npm:preact@10.29.8",
|
|
32
41
|
"preact11": "npm:preact@11.1.1",
|
|
33
42
|
"typescript": "7.0.2"
|