Mobx or immer/immutable adapter for colyseus.js

Hi all!

As colyseus client im using colyseus.js.
Is there a way to get simple changes from server for using with mobx/immer/immutable libraries?

I see few ways to resolve it:

  • Override SchemaSerializer and replace schema with registerSerializer
  • Recursively add onChange/onAdd/onRemove function on each Schema field
  • Get toJSON on each change and replace with current (too slow)

First two ways can't implemented without access to private fields like $changes.

Hi @temka1234,

This is a good question, I know there are 2 experiments for Mobx integration with Colyseus' schema:

When decoding the state, the schema is capable of returning the array containing all changes - this is not exposed by the framework currently, though:

Hi @endel,
Thanks for links!
I tryied to implement mobx adapter in such way and discover that some changes not emitted (collection: splice, clear) but presented in result schema state :(
At the moment i want to implement my decode function, but source schema code is not clear.