@pylonsync/react 0.16.1 → 0.17.0
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/useShard.d.ts +5 -0
- package/package.json +4 -4
- package/src/useShard.ts +14 -2
package/dist/useShard.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface UseShardReturn<TSnapshot = unknown, TInput = unknown> {
|
|
|
16
16
|
ack: number;
|
|
17
17
|
/** The most recent input the shard refused, if any. */
|
|
18
18
|
lastRejection: ShardInputRejection | null;
|
|
19
|
+
/**
|
|
20
|
+
* The shard the hook is connected to. It differs from the `shardId`
|
|
21
|
+
* argument after the server moved the player to another shard.
|
|
22
|
+
*/
|
|
23
|
+
shardId: string;
|
|
19
24
|
connected: boolean;
|
|
20
25
|
error: Error | null;
|
|
21
26
|
/** Send an input to the shard. Returns a client sequence number, or 0
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.17.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"prepack": "bun run build"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@pylonsync/realtime": "0.
|
|
18
|
-
"@pylonsync/sdk": "0.
|
|
19
|
-
"@pylonsync/sync": "0.
|
|
17
|
+
"@pylonsync/realtime": "0.17.0",
|
|
18
|
+
"@pylonsync/sdk": "0.17.0",
|
|
19
|
+
"@pylonsync/sync": "0.17.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": ">=19.0.0"
|
package/src/useShard.ts
CHANGED
|
@@ -55,6 +55,11 @@ export interface UseShardReturn<TSnapshot = unknown, TInput = unknown> {
|
|
|
55
55
|
ack: number;
|
|
56
56
|
/** The most recent input the shard refused, if any. */
|
|
57
57
|
lastRejection: ShardInputRejection | null;
|
|
58
|
+
/**
|
|
59
|
+
* The shard the hook is connected to. It differs from the `shardId`
|
|
60
|
+
* argument after the server moved the player to another shard.
|
|
61
|
+
*/
|
|
62
|
+
shardId: string;
|
|
58
63
|
connected: boolean;
|
|
59
64
|
error: Error | null;
|
|
60
65
|
/** Send an input to the shard. Returns a client sequence number, or 0
|
|
@@ -94,6 +99,7 @@ export function useShard<TSnapshot = unknown, TInput = unknown>(
|
|
|
94
99
|
const [connected, setConnected] = useState<boolean>(false);
|
|
95
100
|
const [error, setError] = useState<Error | null>(null);
|
|
96
101
|
const [entitiesVersion, setEntitiesVersion] = useState<number>(0);
|
|
102
|
+
const [currentShard, setCurrentShard] = useState<string>(shardId);
|
|
97
103
|
|
|
98
104
|
const clientRef = useRef<ShardClient<TSnapshot, TInput> | null>(null);
|
|
99
105
|
|
|
@@ -118,13 +124,14 @@ export function useShard<TSnapshot = unknown, TInput = unknown>(
|
|
|
118
124
|
...options,
|
|
119
125
|
ticket:
|
|
120
126
|
typeof options.ticket === "function"
|
|
121
|
-
? () => {
|
|
127
|
+
? (shard: string) => {
|
|
122
128
|
const current = ticketRef.current;
|
|
123
|
-
return typeof current === "function" ? current() : (current ?? "");
|
|
129
|
+
return typeof current === "function" ? current(shard) : (current ?? "");
|
|
124
130
|
}
|
|
125
131
|
: options.ticket,
|
|
126
132
|
});
|
|
127
133
|
clientRef.current = client;
|
|
134
|
+
setCurrentShard(shardId);
|
|
128
135
|
|
|
129
136
|
client.onSnapshot((snap, t, a) => {
|
|
130
137
|
setSnapshot(snap);
|
|
@@ -132,6 +139,10 @@ export function useShard<TSnapshot = unknown, TInput = unknown>(
|
|
|
132
139
|
setAck(a);
|
|
133
140
|
});
|
|
134
141
|
client.onInputRejected((r) => setLastRejection(r));
|
|
142
|
+
client.onTransfer((to) => {
|
|
143
|
+
setCurrentShard(to);
|
|
144
|
+
setSnapshot(null);
|
|
145
|
+
});
|
|
135
146
|
client.onReplication((_table, _summary, t, a) => {
|
|
136
147
|
setTick(t);
|
|
137
148
|
setAck(a);
|
|
@@ -162,6 +173,7 @@ export function useShard<TSnapshot = unknown, TInput = unknown>(
|
|
|
162
173
|
tick,
|
|
163
174
|
ack,
|
|
164
175
|
lastRejection,
|
|
176
|
+
shardId: currentShard,
|
|
165
177
|
connected,
|
|
166
178
|
error,
|
|
167
179
|
send,
|