Module: Landline::WebSocket::Eventifier

Included in:
WSockWrapper
Defined in:
lib/landline/extensions/websocket.rb

Overview

Event system

Instance Method Summary collapse

Instance Method Details

#off(event, listener) ⇒ Object

Attach event listener



22
23
24
25
# File 'lib/landline/extensions/websocket.rb', line 22

def off(event, listener)
  @__listeners ||= {}
  @__listeners[event]&.delete(listener)
end

#on(event, &listener) ⇒ Object

Attach event listener



12
13
14
15
16
17
# File 'lib/landline/extensions/websocket.rb', line 12

def on(event, &listener)
  @__listeners ||= {}
  @__listeners[event] ||= []
  @__listeners[event].append(listener)
  listener
end