@use-everywhere/core 0.11.0 → 0.11.1
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/llms.txt +84 -0
- package/package.json +12 -3
package/llms.txt
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @use-everywhere/core
|
|
2
|
+
|
|
3
|
+
> The framework-free engine behind `use-everywhere`: shared state, typed
|
|
4
|
+
> messages, presence, leader election and a cross-origin window channel, for any
|
|
5
|
+
> tab, window or worker on an origin. No React, no framework, no server. If you
|
|
6
|
+
> are using React, install `use-everywhere` instead — it re-exports all of this
|
|
7
|
+
> plus the hooks, so importing both is redundant. Ships ESM and CommonJS.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
npm install @use-everywhere/core
|
|
12
|
+
|
|
13
|
+
No runtime dependencies and no peers. Use this package directly only when you
|
|
14
|
+
are NOT using React.
|
|
15
|
+
|
|
16
|
+
## Minimal working example
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createSharedStore } from '@use-everywhere/core';
|
|
20
|
+
|
|
21
|
+
const store = createSharedStore({ name: 'settings' }, { theme: 'light' });
|
|
22
|
+
|
|
23
|
+
// Fires whenever any tab on the origin writes.
|
|
24
|
+
store.subscribe(() => console.log(store.get()));
|
|
25
|
+
|
|
26
|
+
store.set({ theme: 'dark' });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
| Export | Kind | What it does |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `createSharedStore` | factory | Shared state, last-writer-wins per key |
|
|
34
|
+
| `createSharedReducer` | factory | The same, dispatch-shaped |
|
|
35
|
+
| `createChannel` | factory | Typed fire-and-forget pub/sub between tabs |
|
|
36
|
+
| `createPresence` | factory | Who else is open, with heartbeat and pruning |
|
|
37
|
+
| `createLeader` | factory | Lease-and-claim election with a sticky incumbent |
|
|
38
|
+
| `createNamespace` | factory | Prefix every bus name, for micro-frontends |
|
|
39
|
+
| `openWindow` | function | Open a cross-origin window on a typed 1:1 channel |
|
|
40
|
+
| `connectToOpener` | function | The other half, called by the opened page |
|
|
41
|
+
| `newer` | function | The version clock every conflict is settled by |
|
|
42
|
+
| `observeBus` | function | Every wire crossing a bus, in both directions |
|
|
43
|
+
| `enableDebug` | function | Turn on development diagnostics |
|
|
44
|
+
| `getBusNames` | function | Which buses exist right now |
|
|
45
|
+
| `getTransportKind` | function | Which transport a bus resolved to |
|
|
46
|
+
| `getWireSkew` | function | Version skew between this tab and its peers |
|
|
47
|
+
| `BroadcastChannelTransport` | class | The same-origin default |
|
|
48
|
+
| `StorageTransport` | class | `storage`-event fallback |
|
|
49
|
+
| `SharedWorkerTransport` | class | One worker instead of N tabs |
|
|
50
|
+
| `NoopTransport` | class | Does nothing; for SSR and tests |
|
|
51
|
+
| `WindowClosedError` | class | The opened window went away mid-flow |
|
|
52
|
+
| `HandshakeTimeoutError` | class | The cross-origin handshake never completed |
|
|
53
|
+
| `webStorageAdapter` | function | Persist to `localStorage` / `sessionStorage` |
|
|
54
|
+
| `indexedDbAdapter` | function | Persist to IndexedDB |
|
|
55
|
+
| `jsonSerializer` | function | The default serializer for the text paths |
|
|
56
|
+
|
|
57
|
+
## Gotchas
|
|
58
|
+
|
|
59
|
+
- **Shared state never crosses origins.** That is deliberate — two origins are
|
|
60
|
+
two trust domains. Use `openWindow` / `connectToOpener` for that, which is
|
|
61
|
+
explicit, typed, per-message and validated by origin, envelope brand,
|
|
62
|
+
per-connection nonce and source window.
|
|
63
|
+
- **The wire is structured clone.** Functions, class instances, DOM nodes and
|
|
64
|
+
symbols do not survive. Dates, Maps, Sets and typed arrays do. The text
|
|
65
|
+
transports (`StorageTransport`, persistence) go through a serializer instead,
|
|
66
|
+
which is narrower still — see the serialization guide.
|
|
67
|
+
- **Last-writer-wins, per key**, with a `[counter, clientId]` tie-break. It is a
|
|
68
|
+
deterministic resolution, not a merge; use `createSharedReducer` when the
|
|
69
|
+
operations need to compose.
|
|
70
|
+
- **The name is the identity.** A bus name is global to the origin. Two
|
|
71
|
+
independently-written features picking `'store'` are one store. Use
|
|
72
|
+
`createNamespace` to keep them apart.
|
|
73
|
+
- **Call the factories once, at module scope.** They register singletons keyed by
|
|
74
|
+
name; calling one per render or per request builds a new bus each time.
|
|
75
|
+
|
|
76
|
+
## Docs
|
|
77
|
+
|
|
78
|
+
- Full documentation: https://rxova.org/packages/use-everywhere/
|
|
79
|
+
- Agent-facing index: https://rxova.org/packages/use-everywhere/llms.txt
|
|
80
|
+
- Every page as raw markdown: add `.md` to any docs URL
|
|
81
|
+
- Core section: https://rxova.org/packages/use-everywhere/core/overview.md
|
|
82
|
+
- Generated reference: https://rxova.org/packages/use-everywhere/api/core/readme.md
|
|
83
|
+
- Error codes: https://rxova.org/packages/use-everywhere/errors.md
|
|
84
|
+
- Source: https://github.com/rxova/use-everywhere
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@use-everywhere/core",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Cross-tab shared state, events, presence, and cross-origin window channels",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jonatan Kruszewski <jonakrusze@gmail.com>",
|
|
@@ -9,15 +9,23 @@
|
|
|
9
9
|
"url": "git+https://github.com/rxova/use-everywhere.git",
|
|
10
10
|
"directory": "packages/core"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://rxova.org/packages/use-everywhere/core/overview/",
|
|
13
13
|
"bugs": "https://github.com/rxova/use-everywhere/issues",
|
|
14
14
|
"keywords": [
|
|
15
15
|
"broadcastchannel",
|
|
16
|
+
"broadcast-channel",
|
|
16
17
|
"cross-tab",
|
|
18
|
+
"multi-tab",
|
|
19
|
+
"tabs",
|
|
20
|
+
"tab-sync",
|
|
21
|
+
"sync",
|
|
17
22
|
"shared-state",
|
|
23
|
+
"state-management",
|
|
18
24
|
"postmessage",
|
|
19
25
|
"cross-origin",
|
|
26
|
+
"cross-window",
|
|
20
27
|
"presence",
|
|
28
|
+
"leader-election",
|
|
21
29
|
"pubsub"
|
|
22
30
|
],
|
|
23
31
|
"publishConfig": {
|
|
@@ -64,7 +72,8 @@
|
|
|
64
72
|
}
|
|
65
73
|
},
|
|
66
74
|
"files": [
|
|
67
|
-
"dist"
|
|
75
|
+
"dist",
|
|
76
|
+
"llms.txt"
|
|
68
77
|
],
|
|
69
78
|
"size-limit": [
|
|
70
79
|
{
|