@react-remote-state/client 1.1.4 → 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 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
@@ -5598,7 +5598,7 @@ function useRemoteReducer(uri, reducer, gameId) {
5598
5598
  (_a = meta.client) == null ? void 0 : _a.emit("create");
5599
5599
  } else if (!!gameId) {
5600
5600
  let playerCache = (0, import_lodash.flow)(
5601
- () => !!gameId ? sessionStorage.getItem(gameId) : null,
5601
+ () => !!gameId ? storage.getItem(gameId) : null,
5602
5602
  (cache) => !!cache ? JSON.parse(cache) : null
5603
5603
  )();
5604
5604
  if (!!playerCache) {
@@ -5616,12 +5616,12 @@ function useRemoteReducer(uri, reducer, gameId) {
5616
5616
  meta.client.on("assign", (assign) => {
5617
5617
  var _a, _b;
5618
5618
  setMeta(__spreadProps(__spreadValues({}, meta), { localPlayerId: assign.playerId }));
5619
- if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id) && !!(game == null ? void 0 : game.id)) {
5619
+ if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id)) {
5620
5620
  let playerCache = {
5621
5621
  playerId: assign.playerId,
5622
5622
  socketId: (_b = meta.client) == null ? void 0 : _b.id
5623
5623
  };
5624
- sessionStorage.setItem(game.id, JSON.stringify(playerCache));
5624
+ storage.setItem(assign.gameId, JSON.stringify(playerCache));
5625
5625
  }
5626
5626
  });
5627
5627
  meta.client.on(