timostamm / protobuf-ts

Protobuf and RPC for TypeScript
Apache License 2.0
1.1k stars 131 forks source link

Extend Object prototype for message instances #618

Closed eric-higgins-ai closed 8 months ago

eric-higgins-ai commented 11 months ago

After https://github.com/timostamm/protobuf-ts/pull/582, message instances don't behave exactly like simple objects, as their prototype only includes a Symbol("protobuf-ts/message-type") field and is missing fields normally present in a simple object (e.g. constructor). For us, this specifically causes an issue when using mobx to observe changes to message instances - it only allows observing objects that have a constructor method in their prototype that matches the method for simple objects.

This fixes the problem by copying the default object prototype and adding a Symbol("protobuf-ts/message-type") field, rather than starting from an empty prototype.

timostamm commented 8 months ago

@erichiggins0, CI was failing because of an issue with go. Pushed up https://github.com/timostamm/protobuf-ts/pull/636 to your fork.

timostamm commented 8 months ago

Released in v2.9.4