@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 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
- BrowserConnectHandler,
28
- createConnectionStore,
29
- defineApplicationManifest,
30
- } from '@enbox/browser';
31
-
32
- const application = defineApplicationManifest({
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 store.initialize();
35
+ await application.initialize();
42
36
 
43
- // Invoke directly from a click or other user action so the wallet popup opens.
37
+ // Invoke directly from a user action so the wallet popup opens.
44
38
  async function connect(): Promise<void> {
45
- const snapshot = await store.connect();
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 enbox = snapshot.enbox;
50
- // ...use enbox...
43
+ const notes = application.store(NotesStore);
44
+ // Subscribe to notes' resources or run its domain commands.
51
45
  }
52
46
  ```
53
47
 
54
- Create one store for the application lifetime. It owns session restoration,
55
- protocol readiness, grant refresh, facade replacement, and teardown. Call
56
- `disconnect()` on sign-out and `dispose()` when the store is permanently
57
- released.
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. It leaves update
71
- handling to the host; worker-side `activatePolyfills()` retains its existing
72
- immediate takeover behavior.
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