Listener callback casts custom event data back to event.eventData?

21 vues (au cours des 30 derniers jours)
Simon Ahrens
Simon Ahrens le 9 Oct 2018
I have a simple subclass of event.EventData to pass data to listeners:
classdef (ConstructOnLoad) tuningEventData < event.EventData
properties
path
value
end
methods
function obj = tuningEventData(path, value)
obj.path = path;
obj.value = value;
end
end
end
I trigger an event, passing a tuningEventData object:
notify(obj, 'tuningChange', tuningEventData(path, val));
Now I have one listener receiving this and triggering yet another event in its callback method, which I'd like to pass on the same tuningEventData object:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', data);
end
But listeners to this new event do not receive the tuningEventData object. They receive an EventData object instead which obviously doesn't have the path and value properties.
The only way to pass on a tuningEventData object seems to be creating a new object in the first listener's callback:
function handleTuningChange(obj, src, data)
notify(obj, 'tuningChange', tuningEventData(data.path, data.value));
end
Why can't I just send the data object straight on? Is my tuningEventData class missing something?

Réponses (1)

Taylan Kanber
Taylan Kanber le 10 Jan 2022
Change obj.path and obj.value to data.path and data.value

Catégories

En savoir plus sur Events dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by