@react-remote-state/client 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -8,7 +8,7 @@ declare function getPlayer<GameCustom, PlayerCustom>(playerId?: string, game?: G
|
|
8
8
|
} | undefined;
|
9
9
|
declare function isHost<GameCustom, PlayerCustom>(playerId?: string, game?: Game<GameCustom, PlayerCustom>): boolean | undefined;
|
10
10
|
type Reducer<GameCustom, PlayerCustom, Action> = (game: Game<GameCustom, PlayerCustom>, action: Action, playerId: string) => Game<GameCustom, PlayerCustom>;
|
11
|
-
declare function useRemoteReducer<GameCustom, PlayerCustom, Action>(uri: string, reducer: Reducer<GameCustom, PlayerCustom, Action>, gameId?: string): [
|
11
|
+
declare function useRemoteReducer<GameCustom, PlayerCustom, Action>(uri: string, reducer: Reducer<GameCustom, PlayerCustom, Action>, gameId?: string | null, storage?: Storage): [
|
12
12
|
Game<GameCustom, PlayerCustom> | undefined,
|
13
13
|
string | undefined,
|
14
14
|
(action: Action) => void
|
package/dist/index.d.ts
CHANGED
@@ -8,7 +8,7 @@ declare function getPlayer<GameCustom, PlayerCustom>(playerId?: string, game?: G
|
|
8
8
|
} | undefined;
|
9
9
|
declare function isHost<GameCustom, PlayerCustom>(playerId?: string, game?: Game<GameCustom, PlayerCustom>): boolean | undefined;
|
10
10
|
type Reducer<GameCustom, PlayerCustom, Action> = (game: Game<GameCustom, PlayerCustom>, action: Action, playerId: string) => Game<GameCustom, PlayerCustom>;
|
11
|
-
declare function useRemoteReducer<GameCustom, PlayerCustom, Action>(uri: string, reducer: Reducer<GameCustom, PlayerCustom, Action>, gameId?: string): [
|
11
|
+
declare function useRemoteReducer<GameCustom, PlayerCustom, Action>(uri: string, reducer: Reducer<GameCustom, PlayerCustom, Action>, gameId?: string | null, storage?: Storage): [
|
12
12
|
Game<GameCustom, PlayerCustom> | undefined,
|
13
13
|
string | undefined,
|
14
14
|
(action: Action) => void
|
package/dist/index.js
CHANGED
@@ -5572,7 +5572,7 @@ function wrapReducer(reducer) {
|
|
5572
5572
|
}
|
5573
5573
|
};
|
5574
5574
|
}
|
5575
|
-
function useRemoteReducer(uri, reducer, gameId) {
|
5575
|
+
function useRemoteReducer(uri, reducer, gameId, storage = sessionStorage) {
|
5576
5576
|
let [meta, setMeta] = (0, import_react.useState)({
|
5577
5577
|
isHostReady: false,
|
5578
5578
|
isGuestReady: false
|
@@ -5585,7 +5585,9 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5585
5585
|
};
|
5586
5586
|
(0, import_react.useEffect)(() => {
|
5587
5587
|
if (!meta.client) {
|
5588
|
-
|
5588
|
+
setMeta(__spreadProps(__spreadValues({}, meta), {
|
5589
|
+
client: socket_default.connect(uri, { transports: ["websocket"] })
|
5590
|
+
}));
|
5589
5591
|
}
|
5590
5592
|
if (!!meta.client) {
|
5591
5593
|
if (!meta.isGuestReady) {
|
@@ -5596,7 +5598,7 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5596
5598
|
(_a = meta.client) == null ? void 0 : _a.emit("create");
|
5597
5599
|
} else if (!!gameId) {
|
5598
5600
|
let playerCache = (0, import_lodash.flow)(
|
5599
|
-
() => !!gameId ?
|
5601
|
+
() => !!gameId ? storage.getItem(gameId) : null,
|
5600
5602
|
(cache) => !!cache ? JSON.parse(cache) : null
|
5601
5603
|
)();
|
5602
5604
|
if (!!playerCache) {
|
@@ -5614,12 +5616,12 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5614
5616
|
meta.client.on("assign", (assign) => {
|
5615
5617
|
var _a, _b;
|
5616
5618
|
setMeta(__spreadProps(__spreadValues({}, meta), { localPlayerId: assign.playerId }));
|
5617
|
-
if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id)
|
5619
|
+
if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id)) {
|
5618
5620
|
let playerCache = {
|
5619
5621
|
playerId: assign.playerId,
|
5620
5622
|
socketId: (_b = meta.client) == null ? void 0 : _b.id
|
5621
5623
|
};
|
5622
|
-
|
5624
|
+
storage.setItem(assign.gameId, JSON.stringify(playerCache));
|
5623
5625
|
}
|
5624
5626
|
});
|
5625
5627
|
meta.client.on(
|