Class: Dommy::Rack::Trace::DomObserver
- Inherits:
-
Object
- Object
- Dommy::Rack::Trace::DomObserver
- Defined in:
- lib/dommy/rack/trace/dom_observer.rb
Overview
Watches a window's DOM through a MutationObserver and turns raw mutation records into compact summaries (target:, count:/attr:). Pure translation: it holds no event stream and decides nothing about ordering or coalescing — each summary is handed to the block the Trace supplies, which records it. Inert (observes nothing) when the window has no
.Instance Method Summary collapse
-
#initialize(window, &on_summary) ⇒ DomObserver
constructor
A new instance of DomObserver.
Constructor Details
#initialize(window, &on_summary) ⇒ DomObserver
Returns a new instance of DomObserver.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dommy/rack/trace/dom_observer.rb', line 12 def initialize(window, &on_summary) @on_summary = on_summary body = window&.document&.body return unless body @observer = Dommy::MutationObserver.new(window, method(:deliver)) # `observe` is the observer's JS-bridge entry point (Ruby-private), so # drive it through the public bridge call. @observer.__js_call__("observe", [body, {childList: true, subtree: true, attributes: true, characterData: true}]) end |