GitHub Documentation Patreon donate button

setState, @nosync, and other properties



  • I understand that I'm supposed to call setState to initialize my state and that state gets synced. I understand that I should call @nosync for properties inside my state that I do not want synced.

    What happens if I have properties in my room outside the state without @nosync? For example, if I do something like the following, will the secrets property get synced?

    export class BattleRoom extends Room {
    
      onInit (options: any) {
        this.setState({
          players: {}
        });
        this.secrets = {x: 1, y:2}
      }
      // other code omitted
    }
    

  • administrator

    It won't, only the state is synced automatically.



  • Excellent! Thanks for the quick response.

    I was confused on this so I'll summarize in case others come to this post in the future.

    The @nosync decorator is needed because you might create an object foo that will be inside the state object and foo has properties bar and baz with bar being visible and baz being private. You would then use @nosync on baz since it is something inside the state that you want private. But for just other properties of the room but outside the state, those will not be synced.


 

GitHub Documentation Patreon donate button

© 2019 Endel Dreyer