Open
Description
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:
- Only the first
MemberExpression
is checked (state.staticEntities
)
- The
state.staticEntities
may not be available at the time of thecallbacks.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);
});
- Only 1st level of
MemberExpression
is used - If
state.staticEntities
is available, theListen()
callback is triggered immediately. Otherwise, it will be triggered when available. - 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! 🙏