@xmachines/play-vue 2.0.0 → 2.1.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/dist/useActor.js CHANGED
@@ -2,26 +2,29 @@ import { inject, provide } from "vue";
2
2
  import { assertNonNullable } from "@xmachines/play";
3
3
  //#region packages/play-vue/src/useActor.ts
4
4
  /**
5
- * useActor — Vue composable for accessing the provided actor inside a PlayRenderer tree.
6
- *
7
- * Components rendered inside PlayRenderer can call useActor() to reach the actor
8
- * instance without prop drilling.
9
- *
10
- * What is returned is a **swap-following proxy**, not the raw actor object:
11
- * - It is a stable reference for the lifetime of the injection, yet forwards every
12
- * operation (property reads/writes, `in`, `Object.keys` / spread, `instanceof`)
13
- * to whichever actor is CURRENTLY provided so it transparently follows a
14
- * `props.actor` swap on `<ActorProvider>` without consumers re-injecting.
15
- * - Method identity is stable per underlying method: `actor.send === actor.send`
16
- * across repeated reads (allocation-free), and rebinds only when the underlying
17
- * method changes or the actor is swapped.
18
- * - It is NOT `===` the `actor` prop passed to `<ActorProvider>` (it is a distinct
19
- * Proxy object). Any consumer keyed on actor identity most notably a router
20
- * bridge extending `RouterBridgeBase`, whose one-bridge-per-actor guard keys a
21
- * WeakMap on the actor instance — must be given the actor prop itself, not the
22
- * value returned by `useActor()`.
23
- *
24
- * @throws {Error} If called outside a PlayRenderer tree
5
+ * useActor — the Vue composable that gives the actor inside a PlayRenderer tree.
6
+ *
7
+ * A component inside PlayRenderer calls useActor() to reach the actor instance. The
8
+ * actor is then not necessary as a prop.
9
+ *
10
+ * The composable returns a **proxy that follows a swap**, and not the raw actor
11
+ * object:
12
+ * - The proxy is a stable reference for the life of the injection. It forwards
13
+ * every operation (a property read, a property write, `in`, `Object.keys`, a
14
+ * spread, and `instanceof`) to the actor that the tree provides at that moment.
15
+ * Therefore it follows a swap of `props.actor` on `<ActorProvider>`, and a
16
+ * consumer does not inject the actor again.
17
+ * - The identity of each method is stable: `actor.send === actor.send` across
18
+ * repeated reads, with no allocation. The proxy binds the method again only when
19
+ * the method below it changes, or when the tree provides a different actor.
20
+ * - The proxy is NOT `===` the `actor` prop of `<ActorProvider>`, because it is a
21
+ * separate Proxy object. Therefore give the actor prop itself, and not the value
22
+ * of `useActor()`, to each consumer that uses the identity of the actor as a key.
23
+ * The most important such consumer is a router bridge that extends
24
+ * `RouterBridgeBase`: its guard of one bridge for each actor uses the actor
25
+ * instance as the key of a WeakMap.
26
+ *
27
+ * @throws {Error} When the caller is outside a PlayRenderer tree
25
28
  *
26
29
  * @example
27
30
  * ```typescript
@@ -35,11 +38,12 @@ import { assertNonNullable } from "@xmachines/play";
35
38
  */
36
39
  var ActorKey = Symbol("xmachines.actor");
37
40
  /**
38
- * Provide the actor to all descendant components via Vue's inject/provide mechanism.
41
+ * Provides the actor to every descendant component, through the inject and provide
42
+ * mechanism of Vue.
39
43
  *
40
- * Called inside `PlayRenderer.vue`'s `setup()` to make the actor available to any
41
- * child component that calls `useActor()`. Not typically needed outside framework
42
- * internals unless building a custom renderer wrapper.
44
+ * The `setup()` function of `PlayRenderer.vue` calls it. The actor is then
45
+ * available to each child component that calls `useActor()`. You need this function
46
+ * outside the framework internals only when you build your own renderer wrapper.
43
47
  *
44
48
  * @param actor - The actor instance to inject into the component tree.
45
49
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useActor.js","names":[],"sources":["../src/useActor.ts"],"sourcesContent":["/**\n * useActor — Vue composable for accessing the provided actor inside a PlayRenderer tree.\n *\n * Components rendered inside PlayRenderer can call useActor() to reach the actor\n * instance without prop drilling.\n *\n * What is returned is a **swap-following proxy**, not the raw actor object:\n * - It is a stable reference for the lifetime of the injection, yet forwards every\n * operation (property reads/writes, `in`, `Object.keys` / spread, `instanceof`)\n * to whichever actor is CURRENTLY provided so it transparently follows a\n * `props.actor` swap on `<ActorProvider>` without consumers re-injecting.\n * - Method identity is stable per underlying method: `actor.send === actor.send`\n * across repeated reads (allocation-free), and rebinds only when the underlying\n * method changes or the actor is swapped.\n * - It is NOT `===` the `actor` prop passed to `<ActorProvider>` (it is a distinct\n * Proxy object). Any consumer keyed on actor identity most notably a router\n * bridge extending `RouterBridgeBase`, whose one-bridge-per-actor guard keys a\n * WeakMap on the actor instance must be given the actor prop itself, not the\n * value returned by `useActor()`.\n *\n * @throws {Error} If called outside a PlayRenderer tree\n *\n * @example\n * ```typescript\n * import { useActor } from \"@xmachines/play-vue\";\n *\n * const actor = useActor();\n * actor.send({ type: \"SUBMIT\" });\n * ```\n *\n * @packageDocumentation\n */\n\nimport { inject, provide } from \"vue\";\nimport type { InjectionKey } from \"vue\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { AbstractActor } from \"@xmachines/play-actor\";\nimport type { AnyActorLogic } from \"xstate\";\n\n/** Bare actor type accepted by Vue context providers. For the full routing + view shape, use `PlayActor` from `@xmachines/play-router`. */\nexport type AnyPlayActor = AbstractActor<AnyActorLogic>;\n\nexport const ActorKey: InjectionKey<AnyPlayActor> = Symbol(\"xmachines.actor\");\n\n/**\n * Provide the actor to all descendant components via Vue's inject/provide mechanism.\n *\n * Called inside `PlayRenderer.vue`'s `setup()` to make the actor available to any\n * child component that calls `useActor()`. Not typically needed outside framework\n * internals unless building a custom renderer wrapper.\n *\n * @param actor - The actor instance to inject into the component tree.\n */\nexport function provideActor(actor: AnyPlayActor): void {\n\tprovide(ActorKey, actor);\n}\n\nexport function useActor(): AnyPlayActor {\n\treturn assertNonNullable(inject(ActorKey), \"ActorKey\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,WAAuC,OAAO,iBAAiB;;;;;;;;;;AAW5E,SAAgB,aAAa,OAA2B;CACvD,QAAQ,UAAU,KAAK;AACxB;AAEA,SAAgB,WAAyB;CACxC,OAAO,kBAAkB,OAAO,QAAQ,GAAG,UAAU;AACtD"}
1
+ {"version":3,"file":"useActor.js","names":[],"sources":["../src/useActor.ts"],"sourcesContent":["/**\n * useActor — the Vue composable that gives the actor inside a PlayRenderer tree.\n *\n * A component inside PlayRenderer calls useActor() to reach the actor instance. The\n * actor is then not necessary as a prop.\n *\n * The composable returns a **proxy that follows a swap**, and not the raw actor\n * object:\n * - The proxy is a stable reference for the life of the injection. It forwards\n * every operation (a property read, a property write, `in`, `Object.keys`, a\n * spread, and `instanceof`) to the actor that the tree provides at that moment.\n * Therefore it follows a swap of `props.actor` on `<ActorProvider>`, and a\n * consumer does not inject the actor again.\n * - The identity of each method is stable: `actor.send === actor.send` across\n * repeated reads, with no allocation. The proxy binds the method again only when\n * the method below it changes, or when the tree provides a different actor.\n * - The proxy is NOT `===` the `actor` prop of `<ActorProvider>`, because it is a\n * separate Proxy object. Therefore give the actor prop itself, and not the value\n * of `useActor()`, to each consumer that uses the identity of the actor as a key.\n * The most important such consumer is a router bridge that extends\n * `RouterBridgeBase`: its guard of one bridge for each actor uses the actor\n * instance as the key of a WeakMap.\n *\n * @throws {Error} When the caller is outside a PlayRenderer tree\n *\n * @example\n * ```typescript\n * import { useActor } from \"@xmachines/play-vue\";\n *\n * const actor = useActor();\n * actor.send({ type: \"SUBMIT\" });\n * ```\n *\n * @packageDocumentation\n */\n\nimport { inject, provide } from \"vue\";\nimport type { InjectionKey } from \"vue\";\nimport { assertNonNullable } from \"@xmachines/play\";\nimport type { AbstractActor } from \"@xmachines/play-actor\";\nimport type { AnyActorLogic } from \"xstate\";\n\n/**\n * The bare actor type that the Vue context providers accept. For the complete routing and view shape, use `PlayActor` from `@xmachines/play-router`.\n */\nexport type AnyPlayActor = AbstractActor<AnyActorLogic>;\n\nexport const ActorKey: InjectionKey<AnyPlayActor> = Symbol(\"xmachines.actor\");\n\n/**\n * Provides the actor to every descendant component, through the inject and provide\n * mechanism of Vue.\n *\n * The `setup()` function of `PlayRenderer.vue` calls it. The actor is then\n * available to each child component that calls `useActor()`. You need this function\n * outside the framework internals only when you build your own renderer wrapper.\n *\n * @param actor - The actor instance to inject into the component tree.\n */\nexport function provideActor(actor: AnyPlayActor): void {\n\tprovide(ActorKey, actor);\n}\n\nexport function useActor(): AnyPlayActor {\n\treturn assertNonNullable(inject(ActorKey), \"ActorKey\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,WAAuC,OAAO,iBAAiB;;;;;;;;;;;AAY5E,SAAgB,aAAa,OAA2B;CACvD,QAAQ,UAAU,KAAK;AACxB;AAEA,SAAgB,WAAyB;CACxC,OAAO,kBAAkB,OAAO,QAAQ,GAAG,UAAU;AACtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-vue",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Vue renderer for XMachines Play architecture",
5
5
  "keywords": [
6
6
  "reactive",
@@ -41,12 +41,13 @@
41
41
  "lint": "oxlint .",
42
42
  "format": "oxfmt .",
43
43
  "test": "vitest",
44
+ "test:coverage": "vitest run --coverage",
44
45
  "test:watch": "vitest"
45
46
  },
46
47
  "dependencies": {
47
- "@xmachines/play": "2.0.0",
48
- "@xmachines/play-actor": "2.0.0",
49
- "@xmachines/play-signals": "2.0.0"
48
+ "@xmachines/play": "2.1.1",
49
+ "@xmachines/play-actor": "2.1.1",
50
+ "@xmachines/play-signals": "2.1.1"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@testing-library/jest-dom": "^6.9.1",