EntityContext and EntitySet scoped events in JayData 1.2

Author: Peter Aron Zentai September 18th, 2012

, , ,

As of version 1.2 JayData provides EntityContext and EntitySet scoped events regarding operations happening inside the environment. This way you can be notified about any data change the user is about to submit (or has submitted) and these events also let you to interact with the save/update cycles by letting you mutate the entity to be saved or cancel the operation before it gets actually submitted.

Context scoped notification events

On the context scope you can subscribe to general notification events that fire after one or more entity has been created, altered or deleted. These events allow you to subscribe as many listeners as you want but do not provide “peeking” (before event notifications) and also do not let you mutate/cancel the operation. Use the context level events for synchronization scenarios or for general logging, etc notifications. Context scoped events do not have a return value.

The following example creates a product, then modifies it just to delete it at the end – all the way with notifications provided.

Meanwhile on the protocol:


The result:


Set scoped interactive events

Set scoped events can participate in the entity lifecycle (rather then merely observing it) by altering data or cancelling the event. This comes at the cost of multiple event listeners on the same event. One and only one event handler of an event class can be defined per EntitySet instance.  Also, while context scoped event arrive one per entity, set scoped event arrive aggregated if multiple entities of the given type is changed. In the handler you have to iterate through the items array argument to access individual entities.

Set scoped event names follow the <<“before” | “after” + operation>> naming scheme, giving us 8 possible event classes: “beforeCreate”, “afterCreate”, “beforeRead”, “afterRead”, “beforeUpdate”,”afterUpdate”, “beforeDelete”, “afterDelete”.

, , ,