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| perform_event_emitter_callback(event, callback, args) handled = true end handled end |
#off(event, callback) ⇒ Object
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
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
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 |