Events
manager:make
(let manager:make (fun () (...)))
Allows to register events listeners and emit events
Author
Example
(let em (manager:make))
(em.on "myType" (fun (value) (print "This is a callback")))
(em.emit "myType") # => prints "This is a callback" thanks to the registered listener
_check_valid
(let _check_valid (fun (callback) (...)))
Checks if a given callback is valid (is a function or a closure)
Note: Returns true if the callback is a function/closure, false otherwise
Parameter
callback
: the callback to check
Author
Example
(closure._check_valid (fun (param) ())) # => true
(closure._check_valid (fun (param) {})) # => true
(closure._check_valid 5) # => false
on
(let on (fun (typ callback) (...)))
Registers an event listener
Note: Adds a [type callback] list to the listeners list
Parameters
typ
: the type of the event to listen forcallback
: the function/closure that will be called when an event is emitted
Author
Example
(closure.on "myType" (fun (param) ())
emitWith
(let emitWith (fun (val typ) (...)))
Emits an event with a value
Note: Makes a forEach on the listeners list, and calls the callback. Returns a boolean of whether we called at least one listener
Parameters
val
: the emitted valuetyp
: the type of the emitted event
Author
Example
(closure.emitWith 5 "myType")
emit
(let emit (fun (typ) (...)))
Emits an event with no value
Note: Calls emitWith nil
Parameter
typ
: the type of the emitted event
Author
Example
(closure.emit "myType")
removeListenersOfType
(let removeListenersOfType (fun (typ) (...)))
Removes all listeners of a given type
Note: Returns if at least one listener has been removed
Parameter
typ
: the type of event to remove from the list
Author
Example
(closure.remove_listeners_of_type "myType")