Skip to content

Indaxia/lua-eventDispatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lua eventDispatcher

Event Dispatcher implemented in Lua. It can work in the normal object mode or in the WLPM module mode (detected automatically). One of the fundamental modules when building achitecture application. Solves the high сohesion problem. Based on the observer pattern.

Installation

Copy code from /src and use eventDispatcher global

OR use WLPM and import("eventDispatcher")

wlpm install https://github.com/Indaxia/lua-eventDispatcher

Usage

-- Subscription on the event
-- The event param is an object with "data", "name" and "stopPropagation" properties
-- You can set event.stopPropagation = true inside the callback to break current dispatch loop
eventDispatcher.on("my.event.a", function(event)
    print("Callback A 1: " .. event.data)
end)

-- ... another file ...

-- Dispatch with any data  
eventDispatcher.dispatch("my.event.a", "Dispatch A 1 Data")

See test file for details

See on XGM/Russian