Navigation

    Colyseus
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. andrew
    A

    andrew

    @andrew

    Chat Follow Unfollow
    0
    Reputation
    1
    Posts
    736
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with andrew
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    andrew Follow

    Posts made by andrew

    State synchronization not working as expected after a delete

    If I have a state like this:

    @type([Simple]) exampleObjArray = new ArraySchema<Simple>();
    @type(Simple) lastOneAdded: Simple;
    
    export class Simple extends Schema {
      constructor(name: string) {
        super();
        this.name = name;
      }
      @type('string') name: string;
    }
    

    And then modify the state to add one to the array:

    const s = new Simple('simple');
    state.exampleObjArray.push(s);
    state.lastOneAdded = s;
    

    And then do it again later...

    const s = new Simple('simple');
    state.exampleObjArray.push(s);
    state.lastOneAdded = s;
    

    And then I delete from the array:

    state.exampleObjArray.pop();
    

    and then delete again...

    state.exampleObjArray.pop();
    

    And then I change lastOneAdded:

    state.lastOneAdded.name = 'Changed.';
    

    On the client:

    room.onStateChange(s => console.log(s));
    

    s.name remains 'simple' when I would expect 'Changed'
    When I reload the whole page, the state s.name is set to 'Changed'

    Should this kind of data schema be avoided? It would be nice to have data duplicated in the schema, but this seems to be leading to the problem. Is this actually a bug? Or do I just have to make sure not to have data share references?

    I noticed a similar problem when deleting from a MapSchema.

    posted in Questions & Help •