Listener callback casts custom event data back to event.eventData?
12 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Events 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!