Skip to content

Non-observable model properties (like observable.ref) #504

@graphographer

Description

@graphographer

In the continuing tradition of probably not using Keystone as intended, I've been creating a generic Messaging system which expresses notifications, requests, and responses as Keystone models which are synchronized via patches across a websocket.

I ran into an interesting issue, which I have solved, but I'm hoping that maybe there is an easier way.

For example, a Request has a model property called data which is intended to hold the contents of the request. Assume that the request is to apply an action call on the server, and so data should a SerializedActionCall. However, when attached to the model, the action call is made observable and argument values are sometimes transformed in odd ways that I don't understand.

The solution I've come up with is to JSON.stringify serialized action calls and then to de-stringify them in order to apply them. However, I'd like to avoid doing this if possible, so I'm wondering if there's some feature of Keystone models that I've missed that allows a property to be expressed as a plain object (akin to Mobx's observable.ref decorator).

Another theory about what was fouling me up is that my system of using patches is converting serialized action call arguments back into model instances. So perhaps instead of expressing these Messaging model changes as patches I could express them also as actions (a bit meta -- imagine model actions which apply serialized model actions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions