Events

manager:make


(let manager:make (fun () (...))) Allows to register events listeners and emit events

Author

@fabien-zoccola

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

@fabien-zoccola

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 for
  • callback: the function/closure that will be called when an event is emitted

Author

@fabien-zoccola

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 value
  • typ: the type of the emitted event

Author

@fabien-zoccola

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

@fabien-zoccola

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

@fabien-zoccola

Example

(closure.remove_listeners_of_type "myType")