Event listener code example

Hi,

I have a fairly large plugin that is using event dispatching heavily, so when addEventListener and removeEventListener were removed in 2018.3276 I was dreading having to rewrite the code.

Here is what I ended up doing (in example form) using the new stylings of 3276 in case anyone else likes to use dispatching, or needs to update code.

JS Side

//----------------------------------------------------------------------------- // Corona HTML5 Event Listener //----------------------------------------------------------------------------- window.myplugin\_js = { doSomething: function() { this.dispatchEvent({name: 'greet', data: {greeting: "Hello"}}) }, addEventListener: function(listener) { this.dispatcher = LuaCreateFunction(listener); }, removeEventListener: function() { LuaReleaseFunction(this.dispatcher); }, dispatchEvent: function(event) { this.dispatcher(event) } }

Lua side

--############################################################################# --# Corona HTML5 Event Listener --############################################################################# local myplugin = require("myplugin") local function listener(event) if event.name == 'greet' then print(event.data.greeting) --\> Hello end end myplugin.addEventListener(listener) myplugin.doSomething()

Just wanted to share in case anyone needed it. Saved me a lot of rewriting.

-dev