@colyseus/schema 2.0.7 → 2.0.9
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/cjs/index.js +15 -5
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +14 -5
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +15 -5
- package/lib/Schema.d.ts +7 -1
- package/lib/Schema.js +14 -5
- package/lib/Schema.js.map +1 -1
- package/lib/codegen/api.js +19 -0
- package/lib/codegen/api.js.map +1 -1
- package/lib/codegen/parser.js.map +1 -1
- package/package.json +2 -2
- package/src/Schema.ts +18 -4
- package/src/codegen/api.ts +20 -0
- package/src/codegen/parser.ts +5 -5
- package/lib/events/EventEmitter.d.ts +0 -13
- package/lib/events/EventEmitter.js +0 -31
- package/lib/events/EventEmitter.js.map +0 -1
- package/lib/types/index.d.ts +0 -6
- package/lib/types/index.js +0 -13
- package/lib/types/index.js.map +0 -1
package/build/esm/index.mjs
CHANGED
|
@@ -2310,16 +2310,25 @@ class Schema {
|
|
|
2310
2310
|
setDirty(property, operation) {
|
|
2311
2311
|
this.$changes.change(property, operation);
|
|
2312
2312
|
}
|
|
2313
|
-
|
|
2313
|
+
/**
|
|
2314
|
+
* Client-side: listen for changes on property.
|
|
2315
|
+
* @param prop the property name
|
|
2316
|
+
* @param callback callback to be triggered on property change
|
|
2317
|
+
* @param immediate trigger immediatelly if property has been already set.
|
|
2318
|
+
*/
|
|
2319
|
+
listen(prop, callback, immediate = true) {
|
|
2314
2320
|
if (!this.$callbacks) {
|
|
2315
2321
|
this.$callbacks = {};
|
|
2316
2322
|
}
|
|
2317
|
-
if (!this.$callbacks[
|
|
2318
|
-
this.$callbacks[
|
|
2323
|
+
if (!this.$callbacks[prop]) {
|
|
2324
|
+
this.$callbacks[prop] = [];
|
|
2325
|
+
}
|
|
2326
|
+
this.$callbacks[prop].push(callback);
|
|
2327
|
+
if (immediate && this[prop] !== undefined) {
|
|
2328
|
+
callback(this[prop], undefined);
|
|
2319
2329
|
}
|
|
2320
|
-
this.$callbacks[attr].push(callback);
|
|
2321
2330
|
// return un-register callback.
|
|
2322
|
-
return () => spliceOne(this.$callbacks[
|
|
2331
|
+
return () => spliceOne(this.$callbacks[prop], this.$callbacks[prop].indexOf(callback));
|
|
2323
2332
|
}
|
|
2324
2333
|
decode(bytes, it = { offset: 0 }, ref = this) {
|
|
2325
2334
|
const allChanges = [];
|