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
- #emit(event, *args) ⇒ Object
- #off(event, callback) ⇒ Object
- #on(event, callback) ⇒ Object
- #once(event, callback) ⇒ Object
Instance Method Details
#emit(event, *args) ⇒ Object
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| callback.call(*args) handled = true end handled end |
#off(event, callback) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/playwright/event_emitter.rb', line 72 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
53 54 55 56 57 58 |
# File 'lib/playwright/event_emitter.rb', line 53 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
62 63 64 65 66 67 68 |
# File 'lib/playwright/event_emitter.rb', line 62 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 |