@colyseus/schema 4.0.22 → 4.0.23
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/build/decoder/strategy/Callbacks.d.ts +5 -5
- package/build/index.cjs +1 -0
- package/build/index.cjs.map +1 -1
- package/build/index.js +1 -0
- package/build/index.mjs +1 -0
- package/build/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/decoder/strategy/Callbacks.ts +15 -13
package/package.json
CHANGED
|
@@ -88,13 +88,13 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
88
88
|
if (!collection || collection[$refId] === undefined) {
|
|
89
89
|
let removePropertyCallback: () => void;
|
|
90
90
|
removePropertyCallback = this.addCallback(
|
|
91
|
-
instance[$refId]
|
|
91
|
+
instance[$refId]!,
|
|
92
92
|
propertyName,
|
|
93
93
|
(value: TReturn, _: TReturn) => {
|
|
94
94
|
if (value !== null && value !== undefined) {
|
|
95
95
|
// Remove the property listener now that collection is available
|
|
96
96
|
removePropertyCallback();
|
|
97
|
-
removeHandler = this.addCallback(value[$refId]
|
|
97
|
+
removeHandler = this.addCallback(value[$refId]!, operation, handler);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
);
|
|
@@ -113,7 +113,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
return this.addCallback(collection[$refId]
|
|
116
|
+
return this.addCallback(collection[$refId]!, operation, handler);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -162,13 +162,13 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
162
162
|
handler(currentValue, undefined as any);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
return this.addCallback(instance[$refId]
|
|
165
|
+
return this.addCallback(instance[$refId]!, propertyName, handler);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Listen to any property change on an instance.
|
|
170
170
|
*/
|
|
171
|
-
onChange<TInstance extends
|
|
171
|
+
onChange<TInstance extends object>(
|
|
172
172
|
instance: TInstance,
|
|
173
173
|
handler: InstanceChangeCallback
|
|
174
174
|
): () => void;
|
|
@@ -184,7 +184,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
184
184
|
/**
|
|
185
185
|
* Listen to item changes in a nested collection.
|
|
186
186
|
*/
|
|
187
|
-
onChange<TInstance extends
|
|
187
|
+
onChange<TInstance extends object, K extends CollectionPropNames<TInstance>>(
|
|
188
188
|
instance: TInstance,
|
|
189
189
|
property: K,
|
|
190
190
|
handler: KeyValueCallback<CollectionKeyType<TInstance, K>, CollectionValueType<TInstance, K>>
|
|
@@ -195,7 +195,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
195
195
|
// onChange(instance, handler) - instance change
|
|
196
196
|
const instance = args[0] as Schema;
|
|
197
197
|
const handler = args[1] as InstanceChangeCallback;
|
|
198
|
-
return this.addCallback(instance[$refId]
|
|
198
|
+
return this.addCallback(instance[$refId]!, OPERATION.REPLACE, handler);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
if (typeof args[0] === 'string') {
|
|
@@ -229,7 +229,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
229
229
|
/**
|
|
230
230
|
* Listen to items added to a nested collection.
|
|
231
231
|
*/
|
|
232
|
-
onAdd<TInstance
|
|
232
|
+
onAdd<TInstance, K extends CollectionPropNames<TInstance>>(
|
|
233
233
|
instance: TInstance,
|
|
234
234
|
property: K,
|
|
235
235
|
handler: ValueKeyCallback<CollectionValueType<TInstance, K>, CollectionKeyType<TInstance, K>>,
|
|
@@ -269,7 +269,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
269
269
|
/**
|
|
270
270
|
* Listen to items removed from a nested collection.
|
|
271
271
|
*/
|
|
272
|
-
onRemove<TInstance
|
|
272
|
+
onRemove<TInstance, K extends CollectionPropNames<TInstance>>(
|
|
273
273
|
instance: TInstance,
|
|
274
274
|
property: K,
|
|
275
275
|
handler: ValueKeyCallback<CollectionValueType<TInstance, K>, CollectionKeyType<TInstance, K>>
|
|
@@ -299,7 +299,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
299
299
|
* Bind properties from a Schema instance to a target object.
|
|
300
300
|
* Changes will be automatically reflected on the target object.
|
|
301
301
|
*/
|
|
302
|
-
bindTo<TInstance
|
|
302
|
+
bindTo<TInstance, TTarget>(
|
|
303
303
|
from: TInstance,
|
|
304
304
|
to: TTarget,
|
|
305
305
|
properties?: string[],
|
|
@@ -327,7 +327,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
327
327
|
action();
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
return this.addCallback(from[$refId]
|
|
330
|
+
return this.addCallback((from as IRef)[$refId]!, OPERATION.REPLACE, action);
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
protected triggerChanges(allChanges: DataChange[]): void {
|
|
@@ -350,7 +350,7 @@ export class StateCallbackStrategy<TState extends IRef> {
|
|
|
350
350
|
(change.op & OPERATION.DELETE) === OPERATION.DELETE &&
|
|
351
351
|
Schema.isSchema(change.previousValue)
|
|
352
352
|
) {
|
|
353
|
-
const childRefId = (change.previousValue as Ref)[$refId]
|
|
353
|
+
const childRefId = (change.previousValue as Ref)[$refId]!;
|
|
354
354
|
const deleteCallbacks = this.callbacks[childRefId]?.[OPERATION.DELETE];
|
|
355
355
|
if (deleteCallbacks) {
|
|
356
356
|
for (let j = deleteCallbacks.length - 1; j >= 0; j--) {
|
|
@@ -518,8 +518,10 @@ export const Callbacks = {
|
|
|
518
518
|
return getDecoderStateCallbacks(roomOrDecoder);
|
|
519
519
|
|
|
520
520
|
} else if ('decoder' in roomOrDecoder.serializer) {
|
|
521
|
-
return getDecoderStateCallbacks(roomOrDecoder.serializer.decoder);
|
|
521
|
+
return getDecoderStateCallbacks((roomOrDecoder.serializer as { decoder: Decoder<T> }).decoder);
|
|
522
522
|
}
|
|
523
|
+
|
|
524
|
+
throw new Error('Invalid room or decoder');
|
|
523
525
|
},
|
|
524
526
|
|
|
525
527
|
getRawChanges(decoder: Decoder, callback: (changes: DataChange[]) => void) {
|