Response title
This is preview!
Since within the getter code (shown below) the data is set to the result (if any) of the getData event handlers execution then the last event handler in the sequence of getData handlers which returns some value has a chance to return value which differs from the one which is currently stored.
a) setData event (as you surely noticed) is not of much use for the following reasons:
i. It is fired before the data is actually setii. It does not influence further execution of the setter. I'd like to have some means to "... prevent the value from being set" depending of the event handlers execution, but it is not currently the case.The only (cumbersome) solution can consist in saving original data value using setData handler and then resetting the value back to its original state within changeData handler.
b) But we still can set different value using new "changeData" event.The event was added as a request from jquery-datalink plugin development team exactly for the purpose we are interested in - to make it possible to override the value which is assigned to the data object. But since the data has already been set then we can only abort current sequence of event handlers and set our own value which will be further rippled to all other subscribers. We need take into account that the value must be set in a way which won't cause endless recursion. So we have to use either jQuery.data utility method (which does not trigger any events) or, as one of the possible solutions, set some flag to indicate that our data tampering hander is currently running.
© 2013 jQuery Foundation
Sponsored by and others.