Module: Playwright::EventEmitter

Included in:
Channel, ChannelOwner, EventEmitterProxy
Defined in:
lib/playwright/event_emitter.rb

Overview

A subset of Events/EventEmitter in Node.js

Instance Method Summary collapse

Instance Method Details

#emit(event, *args) ⇒ Object

Parameters:

  • event (String)


38
39
40
41
42
43
44
45
# File 'lib/playwright/event_emitter.rb', line 38

def emit(event, *args)
  handled = false
  (@__event_emitter ||= {})[event.to_s]&.each do |callback|
    perform_event_emitter_callback(event, callback, args)
    handled = true
  end
  handled
end

#off(event, callback) ⇒ Object

Parameters:

  • event (String)
  • callback (Proc)

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
85
# File 'lib/playwright/event_emitter.rb', line 77

def off(event, callback)
  raise ArgumentError.new('callback must not be nil') if callback.nil?

  cb = (@__event_emitter_callback ||= {})["#{event}/#{callback.object_id}"]
  if cb
    (@__event_emitter ||= {})[event.to_s]&.delete(cb)
  end
  self
end

#on(event, callback) ⇒ Object

Parameters:

  • event (String)
  • callback (Proc)

Raises:

  • (ArgumentError)


58
59
60
61
62
63
# File 'lib/playwright/event_emitter.rb', line 58

def on(event, callback)
  raise ArgumentError.new('callback must not be nil') if callback.nil?
  cb = (@__event_emitter_callback ||= {})["#{event}/#{callback.object_id}"] ||= EventEmitterCallback.new(callback)
  ((@__event_emitter ||= {})[event.to_s] ||= Set.new) << cb
  self
end

#once(event, callback) ⇒ Object

Parameters:

  • event (String)
  • callback (Proc)

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
# File 'lib/playwright/event_emitter.rb', line 67

def once(event, callback)
  raise ArgumentError.new('callback must not be nil') if callback.nil?

  cb = (@__event_emitter_callback ||= {})["#{event}/once/#{callback.object_id}"] ||= EventEmitterOnceCallback.new(callback)
  ((@__event_emitter ||= {})[event.to_s] ||= Set.new) << cb
  self
end