I'm a little confused as to when to dispatch an event, and when just to do a direct callback.
It makes sense to me to dispatch events in games, when many objects may be listening, but with UIKit items, such as a button tap, then very likely only that one button is listening. Or if you have a delegate callback from selecting a UITableView row, it would make sense to me to make that a callback rather than dispatching an event.
In Objective C, I would be doing a one function call on pressing a button. I think the NSNotification is the equivalent of dispatching an event, and I try only to use very few in an app, as they are fairly hard to keep track of.
This means that if I were to have a UIButton then I wouldn't have to inherit from GEventDispatcherProxy. Would I? I could just do the onButtonPress function in the plugin, which directly calls a Lua function.
Am I over-thinking this? Does it matter?
Comments
The callback would serve more specific role where as an event would be handled or ignored and can be bubbled to the super/parent if not handled.
The choice of using either is entirely upto you and to the design of the app.
Likes: MikeHart
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
For example, it's possible to develop a UIButton class without using GEventDispatcherProxy and then you can add a function like addTarget which accepts a callback function.