Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 704 Bytes

event-bus.md

File metadata and controls

30 lines (26 loc) · 704 Bytes

Kopytko Framework: EventBus

The mechanism to communicate between various entities in the app. It uses global scope and implements Pub/Sub design pattern.

Example of usage:

sub init()
  eventBus = EventBusFacade()
  eventBus.on("OPEN_MODAL", _handler)
  ' or with a context:
  handler = {
    callThis: sub (payload as Object): ?payload end sub
  }
  eventBus.on("OPEN_MODAL", handler.callThis, handler)
end sub

sub _handler(payload as Object)
  ?payload
end sub

' Some other entity
sub init()
  eventBus = EventBusFacade()
  eventBus.trigger("OPEN_MODAL", { title: "I am title" })
end sub

To remove listener simply do:

eventBus.off("OPEN_MODAL", _handler)