@spine-event-engine/client-react 2.0.0-snapshot.2 → 2.0.0-snapshot.5

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.
Files changed (2) hide show
  1. package/README.md +54 -10
  2. package/package.json +3 -4
package/README.md CHANGED
@@ -7,9 +7,29 @@ system.
7
7
 
8
8
  For detailed hook lifecycles and error behavior, read the [reference](REFERENCE.md).
9
9
 
10
- The [browser client and gateway guide](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
10
+ The [browser client and gateway guide](https://github.com/SpineEventEngine/spine-ts/blob/main/docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
11
11
  explains the subscription and authentication limits inherited from the browser client.
12
12
 
13
+ ## Install and prepare an application
14
+
15
+ This is an experimental snapshot. Install React and its type package as peers,
16
+ then install both Spine client packages in an application that already owns a
17
+ generated Proto model. Include every direct import used by the examples:
18
+
19
+ ```sh
20
+ pnpm add react@^19.2.8 @types/react@^19.2.7
21
+ pnpm add @bufbuild/protobuf@2.12.1 @spine-event-engine/core@snapshot @spine-event-engine/proto@snapshot @spine-event-engine/client-web@snapshot @spine-event-engine/client-react@snapshot
22
+ ```
23
+
24
+ Generate and publish the application's model schemas using the [Proto tools
25
+ guide](https://github.com/SpineEventEngine/spine-ts/tree/main/packages/proto-tools#readme). The Message Board schema in this guide is a
26
+ repository example of such output; it is not a public dependency to install.
27
+
28
+ The application, not React, creates the authenticated Gateway connection and
29
+ chooses its session policy. Keep the `Client` outside React rendering and close
30
+ it when the application unmounts or shuts down. See the [reference](REFERENCE.md)
31
+ for hook and cleanup details.
32
+
13
33
  ## 💡 Why use it?
14
34
 
15
35
  - ✅ Provides a stable Spine request scope to a React tree.
@@ -22,16 +42,31 @@ explains the subscription and authentication limits inherited from the browser c
22
42
  Create the browser client outside rendering, select an actor scope, and provide
23
43
  that stable scope to React descendants.
24
44
 
45
+ <!-- docs-snippet-path: examples/message-board/web/src/docs/client-react-provider-query.ts -->
46
+
25
47
  ```ts
26
- import { createElement } from "react";
27
- import { Client } from "@spine-event-engine/client-web";
48
+ import { create } from "@bufbuild/protobuf";
49
+ import { TypeUrls } from "@spine-event-engine/core";
28
50
  import { SpineClientProvider, useEntityQuery } from "@spine-event-engine/client-react";
51
+ import { Client } from "@spine-event-engine/client-web";
52
+ import { BoardMessageViewSchema } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/message_board_pb.js";
53
+ import { QueryIdSchema, QuerySchema, TargetSchema } from "@spine-event-engine/proto/client";
54
+ import { createElement } from "react";
29
55
 
30
- const client = Client.forGrpcWeb("https://api.example.test");
56
+ const client = Client.forGrpcWeb("http://127.0.0.1:8080");
31
57
  const request = client.onBehalfOf("alice");
32
58
 
59
+ const taskQuery = () =>
60
+ create(QuerySchema, {
61
+ id: create(QueryIdSchema, { value: "messages" }),
62
+ target: create(TargetSchema, {
63
+ type: TypeUrls.derive(BoardMessageViewSchema),
64
+ criterion: { case: "includeAll", value: true },
65
+ }),
66
+ });
67
+
33
68
  function Tasks() {
34
- const result = useEntityQuery(() => buildTaskQuery(), []);
69
+ const result = useEntityQuery(taskQuery, []);
35
70
  return createElement("output", undefined, result.status);
36
71
  }
37
72
 
@@ -39,10 +74,18 @@ function App() {
39
74
  return createElement(SpineClientProvider, { request }, createElement(Tasks));
40
75
  }
41
76
 
42
- declare function buildTaskQuery(): Parameters<typeof request.send>[0];
77
+ async function stopApplication() {
78
+ await client.close();
79
+ }
80
+
43
81
  void App;
82
+ void stopApplication;
44
83
  ```
45
84
 
85
+ Call `stopApplication()` from the application's unmount or shutdown path. The
86
+ schema import is an application-generated model contract, not an installable
87
+ Message Board package.
88
+
46
89
  `use...` names are reserved for this React adapter because each one is a React
47
90
  hook. Application code otherwise uses the client verbs such as `post`, `send`,
48
91
  `createSubscription`, `activate`, and `cancel`.
@@ -52,11 +95,13 @@ hook. Application code otherwise uses the client verbs such as `post`, `send`,
52
95
  An Entity subscription needs an authoritative query for reconnect recovery.
53
96
  The hook starts and cancels it after React commits the component.
54
97
 
98
+ <!-- docs-snippet-path: examples/message-board/web/src/docs/client-react-subscription.ts -->
99
+
55
100
  ```ts
56
- // docs-snippet-path: examples/message-board/web/src/index.tsx
57
101
  import { create } from "@bufbuild/protobuf";
58
102
  import { TypeUrls } from "@spine-event-engine/core";
59
103
  import { useEntitySubscription, useSubscriptionDelivery } from "@spine-event-engine/client-react";
104
+ import { BoardMessageViewSchema } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/message_board_pb.js";
60
105
  import {
61
106
  QueryIdSchema,
62
107
  QuerySchema,
@@ -64,7 +109,6 @@ import {
64
109
  TopicIdSchema,
65
110
  TopicSchema,
66
111
  } from "@spine-event-engine/proto/client";
67
- import { BoardMessageViewSchema } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/message_board_pb.js";
68
112
 
69
113
  const target = create(TargetSchema, {
70
114
  type: TypeUrls.derive(BoardMessageViewSchema),
@@ -92,6 +136,6 @@ a possible gap.
92
136
 
93
137
  ## 🔗 Learn more
94
138
 
95
- - [Browser client](../client-web/README.md)
96
- - [Message Board web example](../../examples/message-board/web/README.md)
139
+ - [Browser client](https://github.com/SpineEventEngine/spine-ts/blob/main/packages/client-web/README.md)
140
+ - [Message Board web example](https://github.com/SpineEventEngine/spine-ts/blob/main/examples/message-board/web/README.md)
97
141
  - [Detailed coding-agent reference](REFERENCE.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spine-event-engine/client-react",
3
- "version": "2.0.0-snapshot.2",
3
+ "version": "2.0.0-snapshot.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {
@@ -10,8 +10,7 @@
10
10
  },
11
11
  "publishConfig": {
12
12
  "registry": "https://registry.npmjs.org/",
13
- "access": "public",
14
- "tag": "snapshot"
13
+ "access": "public"
15
14
  },
16
15
  "description": "React observers for the browser-safe Spine client.",
17
16
  "exports": {
@@ -30,7 +29,7 @@
30
29
  "react": "^19.2.8"
31
30
  },
32
31
  "dependencies": {
33
- "@spine-event-engine/client-web": "2.0.0-snapshot.2"
32
+ "@spine-event-engine/client-web": "2.0.0-snapshot.5"
34
33
  },
35
34
  "scripts": {
36
35
  "check:dependencies": "node ../../scripts/check-client-react-dependencies.mjs"