Class: Browser::DOM::MutationObserver
- Includes:
- Native
- Defined in:
- opal/browser/dom/mutation_observer.rb
Overview
A MutationObserver is a performant way to observe changes in the DOM, either on the tree, the attributes or data.
Defined Under Namespace
Classes: Record
Class Method Summary collapse
Instance Method Summary collapse
-
#disconnect ⇒ Object
Disconnect the observer, thus stopping observing any changes.
-
#initialize {|records| ... } ⇒ MutationObserver
constructor
Create a new MutationObserver with the given block.
-
#observe(target, options = nil) ⇒ Object
Observe the given target with the given options.
-
#take ⇒ Array<Record>
Empty the observer queue and return its contents.
Constructor Details
#initialize {|records| ... } ⇒ MutationObserver
Create a new MutationObserver with the given block.
89 90 91 92 93 94 95 96 97 |
# File 'opal/browser/dom/mutation_observer.rb', line 89 def initialize(&block) %x{ var func = function(records) { return #{block.call(`records`.map { |r| Browser::DOM::MutationObserver::Record.new(r) })}; } } super(`new window.MutationObserver(func)`) end |
Class Method Details
Instance Method Details
#disconnect ⇒ Object
Disconnect the observer, thus stopping observing any changes.
138 139 140 |
# File 'opal/browser/dom/mutation_observer.rb', line 138 def disconnect `#@native.disconnect()` end |
#observe(target, options = nil) ⇒ Object
Observe the given target with the given options.
The supported options are:
- children - whether to observe changes on the children of the target or not
- tree - whether to observe changes on the whole subtree or not
- attributes - whether to observe changes to attributes or not,
if the value is
:old
the old value will be saved - cdata - whether to observe changes to CDATA sections or not,
if the value is
:old
the old value will be saved - filter - array of attribute names to observe
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'opal/browser/dom/mutation_observer.rb', line 115 def observe(target, = nil) unless = { children: true, tree: true, attributes: :old, cdata: :old } end `#@native.observe(#{Native.convert(target)}, #{convert()})` self end |