Skip to content

Commit

Permalink
add FIXME/workaround comment for .listen() as well. #147
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Mar 30, 2024
1 parent c29b5c9 commit 4ff57bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/decoder/strategy/StateCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ export function getStateCallbacks(decoder: Decoder) {
return new Proxy({
listen: function listen(prop: string, callback: (value: any, previousValue: any) => void, immediate: boolean = true) {
// immediate trigger
if (immediate && context.instance[prop] !== undefined) {
if (
immediate &&
context.instance[prop] !== undefined &&
!isTriggeringOnAdd // FIXME: This is a workaround
// (https://github.com/colyseus/schema/issues/147)
) {
callback(context.instance[prop], undefined);
}
return $root.addCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ $(decoder.state).teams.onAdd((team, index) => { // delayed
$(team).entities.onAdd((entity, entityId) => {
console.log(`Entities.onAdd =>`, { teamIndex: index, entityId, refId: decoder.$root.refIds.get(entity) });

// $(entity).onChange(() => {
// console.log("Entity changed!");
// });
$(entity).onChange(() => {
console.log("Entity changed!");
});

$(entity).listen("position", (value, previousValue) => {
console.log("entity position ->", value.toJSON());
Expand Down

0 comments on commit 4ff57bd

Please sign in to comment.