Skip to content

Nested Schema Callbacks #237

Open
Open
@endel

Description

@endel

The schema callback system has changed on 0.16.

Currently, it is not possible to attach callback to a nested property, like this:

callbacks.OnAdd(state => state.staticEntities.entities, OnAdded);
callbacks.OnAdd(state => state.staticEntities.entities, OnRemoved);

This does not work because:

  1. Only the first MemberExpression is checked (state.staticEntities)

var memberExpression = (MemberExpression)propertyExpression.Body;
var propertyName = memberExpression.Member.Name;

  1. The state.staticEntities may not be available at the time of the callbacks.OnAdd() call, as the client may not have received it from the server yet.

The following works:

callbacks.Listen(state => state.staticEntities, (staticEntities, _) => {
    callbacks.OnAdd(staticEntities, s => s.entities, OnAdded);
    callbacks.OnAdd(staticEntities, s => s.entities, OnRemoved);
});
  1. Only 1st level of MemberExpression is used
  2. If state.staticEntities is available, the Listen() callback is triggered immediately. Otherwise, it will be triggered when available.
  3. We provide the parent instance as argument for the next callbacks.OnAdd() calls.

Adding nested callbacks can still be confusing.

I believe that with some more thought and experimentation it could be possible to allow nested evaluation of the expressions, and automatically bind .Listen() methods under the hood in order to support the initial use-case that doesn't work currently.

If anybody from the community would like to pick up this issue, a PR is really appreciated! 🙏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions