Class: Browser::DOM::MutationObserver::Record

Inherits:
Object
  • Object
show all
Includes:
Native
Defined in:
opal/browser/dom/mutation_observer.rb

Overview

Encapsulates a recorded change.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#added ⇒ NodeSet (readonly)

Returns the added nodes.

Returns:



45
46
47
48
49
50
51
52
53
# File 'opal/browser/dom/mutation_observer.rb', line 45

def added
  array = if `#@native.addedNodes != null`
    Native::Array.new(`#@native.addedNodes`)
  else
    []
  end

  NodeSet[array]
end

#name ⇒ String (readonly)

Returns the name of the attribute.

Returns:

  • (String) —

    the name of the attribute



79
# File 'opal/browser/dom/mutation_observer.rb', line 79

alias_native :name, :attributeName

#namespace ⇒ String (readonly)

Returns the namespace of the attribute.

Returns:

  • (String) —

    the namespace of the attribute



83
# File 'opal/browser/dom/mutation_observer.rb', line 83

alias_native :namespace, :attributeNamespace

#old ⇒ String (readonly)

Returns the old value.

Returns:



75
# File 'opal/browser/dom/mutation_observer.rb', line 75

alias_native :old, :oldValue

#removed ⇒ NodeSet (readonly)

Returns the removed nodes.

Returns:



57
58
59
60
61
62
63
64
65
# File 'opal/browser/dom/mutation_observer.rb', line 57

def removed
  array = if `#@native.removedNodes != null`
    Native::Array.new(`#@native.removedNodes`)
  else
    []
  end

  NodeSet[array]
end

#target ⇒ Node (readonly)

Returns the node the mutation affected.

Returns:

  • (Node) —

    the node the mutation affected



69
70
71
# File 'opal/browser/dom/mutation_observer.rb', line 69

def target
  DOM(`#@native.target`)
end

#type ⇒ :attributes, ... (readonly)

Returns the type of the recorded change.

Returns:

  • (:attributes, :tree, :cdata) —

    the type of the recorded change



20
21
22
23
24
25
26
# File 'opal/browser/dom/mutation_observer.rb', line 20

def type
  case `#@native.type`
  when :attributes    then :attribute
  when :childList     then :tree
  when :characterData then :cdata
  end
end

Instance Method Details

#attribute? ⇒ Boolean

Returns true if the change happened on attributes.

Returns:

  • (Boolean)


29
30
31
# File 'opal/browser/dom/mutation_observer.rb', line 29

def attribute?
  type == :attribute
end

#cdata? ⇒ Boolean

Returns true if the change happened in a CDATA section.

Returns:

  • (Boolean)


39
40
41
# File 'opal/browser/dom/mutation_observer.rb', line 39

def cdata?
  type == :cdata
end

#tree? ⇒ Boolean

Returns true if the change happened on the tree.

Returns:

  • (Boolean)


34
35
36
# File 'opal/browser/dom/mutation_observer.rb', line 34

def tree?
  type == :tree
end