@enbox/browser 0.3.83 → 0.3.85
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 +29 -25
- package/dist/browser.mjs +161 -161
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/application.js +37 -0
- package/dist/esm/application.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web-features.js +3 -2
- package/dist/esm/web-features.js.map +1 -1
- package/dist/types/application.d.ts +26 -0
- package/dist/types/application.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/web-features.d.ts +2 -0
- package/dist/types/web-features.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/application.ts +69 -0
- package/src/index.ts +2 -0
- package/src/web-features.ts +3 -2
package/README.md
CHANGED
|
@@ -23,38 +23,41 @@ bun add @enbox/browser
|
|
|
23
23
|
wallet connect handler, and DWeb helpers:
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
protocols: [NotesProtocol],
|
|
34
|
-
} as const);
|
|
35
|
-
const store = createConnectionStore({
|
|
36
|
-
application,
|
|
37
|
-
connectHandler: BrowserConnectHandler({ appName: 'Notes' }),
|
|
38
|
-
monitor: { autoRefresh: {} },
|
|
26
|
+
import { createApplication } from '@enbox/browser';
|
|
27
|
+
import { NotesStore } from './features/notes/store.js';
|
|
28
|
+
|
|
29
|
+
const application = createApplication({
|
|
30
|
+
stores: { notes: NotesStore },
|
|
31
|
+
wallet: { appName: 'Notes' },
|
|
32
|
+
connection: { monitor: { autoRefresh: {} } },
|
|
39
33
|
});
|
|
40
34
|
|
|
41
|
-
await
|
|
35
|
+
await application.initialize();
|
|
42
36
|
|
|
43
|
-
// Invoke directly from a
|
|
37
|
+
// Invoke directly from a user action so the wallet popup opens.
|
|
44
38
|
async function connect(): Promise<void> {
|
|
45
|
-
const snapshot = await
|
|
39
|
+
const snapshot = await application.connection.connect();
|
|
46
40
|
if (snapshot.phase !== 'connected') {
|
|
47
41
|
throw snapshot.error ?? new Error('Connection was not established.');
|
|
48
42
|
}
|
|
49
|
-
const
|
|
50
|
-
//
|
|
43
|
+
const notes = application.store(NotesStore);
|
|
44
|
+
// Subscribe to notes' resources or run its domain commands.
|
|
51
45
|
}
|
|
52
46
|
```
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`disconnect()`
|
|
57
|
-
|
|
48
|
+
Keep one application for the browser lifetime. It derives the manifest from
|
|
49
|
+
feature protocols and owns the connection, session-scoped resources, commands,
|
|
50
|
+
and cleanup. `application.connection.disconnect()` signs out;
|
|
51
|
+
`application.dispose()` permanently tears down the owner. React binds the same
|
|
52
|
+
runtime through `EnboxProvider application={application}`.
|
|
53
|
+
|
|
54
|
+
For a custom host, supply `connectHandler` instead of `wallet`, or supply a
|
|
55
|
+
`connection: manifest => nativeConnection` factory that owns all native
|
|
56
|
+
configuration. The headless `@enbox/api` constructor requires that factory;
|
|
57
|
+
the browser constructor supplies browser defaults around the same runtime.
|
|
58
|
+
Native connection, record, and context primitives remain available for custom
|
|
59
|
+
flows. `defineStore`'s `observe()` factory owns all native view types through
|
|
60
|
+
one subscription and cleanup mechanism.
|
|
58
61
|
|
|
59
62
|
## Browser runtime
|
|
60
63
|
|
|
@@ -67,9 +70,10 @@ Before initializing the connection store, await `prepareBrowser(workerUrl,
|
|
|
67
70
|
{ registrationOptions: { type: 'module' } })` for a module worker, or pass an
|
|
68
71
|
existing registration from this page's `navigator.serviceWorker` when a PWA
|
|
69
72
|
tool owns registration. The helper waits for that worker to control the page
|
|
70
|
-
and activates page polyfills, with a timeout and abort signal.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
and activates page polyfills, with a timeout and abort signal. The application
|
|
74
|
+
owns update activation. Worker-side `activatePolyfills()` claims clients during
|
|
75
|
+
activation, but leaves waiting workers in place. Complete pending application
|
|
76
|
+
work before your update handler requests `skipWaiting()` and reloads the page.
|
|
73
77
|
|
|
74
78
|
Current browser-conditioned packages work in page and worker builds without
|
|
75
79
|
Enbox-specific Node-global, `process`, or IIFE shims. Follow the
|