@colyseus/react 0.1.2 → 0.1.4

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/index.cjs CHANGED
@@ -108,9 +108,9 @@ function createSnapshot(node, ctx) {
108
108
  const savedParentRefId = ctx.currentParentRefId;
109
109
  ctx.currentParentRefId = refId;
110
110
  let result;
111
- if (node instanceof _colyseus_schema.MapSchema) result = createSnapshotForMapSchema(node, previousResult, ctx);
112
- else if (node instanceof _colyseus_schema.ArraySchema) result = createSnapshotForArraySchema(node, previousResult, ctx);
113
- else if (node instanceof _colyseus_schema.Schema) result = createSnapshotForSchema(node, previousResult, ctx);
111
+ if (typeof node["set"] === "function") result = createSnapshotForMapSchema(node, previousResult, ctx);
112
+ else if (typeof node["push"] === "function") result = createSnapshotForArraySchema(node, previousResult, ctx);
113
+ else if (_colyseus_schema.Schema.isSchema(node)) result = createSnapshotForSchema(node, previousResult, ctx);
114
114
  else result = node;
115
115
  ctx.currentParentRefId = savedParentRefId;
116
116
  if (refId !== -1) ctx.currentResultsByRefId.set(refId, result);
@@ -151,6 +151,7 @@ function getOrCreateSubscription(roomState, decoder) {
151
151
  originalDecode: decoder.decode
152
152
  };
153
153
  decoder.decode = function(...args) {
154
+ subscription.dirtyRefIds.clear();
154
155
  const changes = subscription.originalDecode.apply(decoder, args);
155
156
  if (changes && changes.length > 0) {
156
157
  const refs = decoder.root?.refs;
@@ -227,7 +228,6 @@ function useColyseusState(roomState, decoder, selector = (s) => s) {
227
228
  const result = createSnapshot(selectedState, ctx);
228
229
  for (const [refId, value] of ctx.currentResultsByRefId) subscription.previousResultsByRefId.set(refId, value);
229
230
  subscription.objectToRefId = ctx.objectToRefId;
230
- subscription.dirtyRefIds.clear();
231
231
  if (++subscription.cleanupCounter >= 100 && ctx.refs) {
232
232
  subscription.cleanupCounter = 0;
233
233
  for (const refId of subscription.previousResultsByRefId.keys()) if (!ctx.refs.has(refId)) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useRef, useSyncExternalStore } from "react";
2
- import { ArraySchema, MapSchema, Schema } from "@colyseus/schema";
2
+ import { Schema } from "@colyseus/schema";
3
3
 
4
4
  //#region src/schema/createSnapshot.ts
5
5
  /**
@@ -108,9 +108,9 @@ function createSnapshot(node, ctx) {
108
108
  const savedParentRefId = ctx.currentParentRefId;
109
109
  ctx.currentParentRefId = refId;
110
110
  let result;
111
- if (node instanceof MapSchema) result = createSnapshotForMapSchema(node, previousResult, ctx);
112
- else if (node instanceof ArraySchema) result = createSnapshotForArraySchema(node, previousResult, ctx);
113
- else if (node instanceof Schema) result = createSnapshotForSchema(node, previousResult, ctx);
111
+ if (typeof node["set"] === "function") result = createSnapshotForMapSchema(node, previousResult, ctx);
112
+ else if (typeof node["push"] === "function") result = createSnapshotForArraySchema(node, previousResult, ctx);
113
+ else if (Schema.isSchema(node)) result = createSnapshotForSchema(node, previousResult, ctx);
114
114
  else result = node;
115
115
  ctx.currentParentRefId = savedParentRefId;
116
116
  if (refId !== -1) ctx.currentResultsByRefId.set(refId, result);
@@ -151,6 +151,7 @@ function getOrCreateSubscription(roomState, decoder) {
151
151
  originalDecode: decoder.decode
152
152
  };
153
153
  decoder.decode = function(...args) {
154
+ subscription.dirtyRefIds.clear();
154
155
  const changes = subscription.originalDecode.apply(decoder, args);
155
156
  if (changes && changes.length > 0) {
156
157
  const refs = decoder.root?.refs;
@@ -227,7 +228,6 @@ function useColyseusState(roomState, decoder, selector = (s) => s) {
227
228
  const result = createSnapshot(selectedState, ctx);
228
229
  for (const [refId, value] of ctx.currentResultsByRefId) subscription.previousResultsByRefId.set(refId, value);
229
230
  subscription.objectToRefId = ctx.objectToRefId;
230
- subscription.dirtyRefIds.clear();
231
231
  if (++subscription.cleanupCounter >= 100 && ctx.refs) {
232
232
  subscription.cleanupCounter = 0;
233
233
  for (const refId of subscription.previousResultsByRefId.keys()) if (!ctx.refs.has(refId)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "tsdown --watch --format esm,cjs",