Class: Dommy::PerformanceObserver

Inherits:
Object
  • Object
show all
Includes:
Internal::ObservableCallback
Defined in:
lib/dommy/performance_observer.rb

Overview

‘PerformanceObserver` — stub. Same observe/disconnect shape, with `__trigger__` for tests.

Spec: w3c.github.io/performance-timeline/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback) ⇒ PerformanceObserver

Returns a new instance of PerformanceObserver.



13
14
15
16
# File 'lib/dommy/performance_observer.rb', line 13

def initialize(callback)
  @callback = callback
  @entry_types = []
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



11
12
13
# File 'lib/dommy/performance_observer.rb', line 11

def callback
  @callback
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/dommy/performance_observer.rb', line 44

def __js_call__(method, args)
  case method
  when "observe"
    observe(args[0])
  when "disconnect"
    disconnect
  when "takeRecords"
    take_records
  end
end

#__trigger__(entries) ⇒ Object



40
41
42
# File 'lib/dommy/performance_observer.rb', line 40

def __trigger__(entries)
  invoke_callback(entries)
end

#disconnectObject



25
26
27
28
# File 'lib/dommy/performance_observer.rb', line 25

def disconnect
  @entry_types = []
  nil
end

#entry_typesObject



36
37
38
# File 'lib/dommy/performance_observer.rb', line 36

def entry_types
  @entry_types.dup
end

#observe(options = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/dommy/performance_observer.rb', line 18

def observe(options = nil)
  opts = options.is_a?(Hash) ? options : {}
  types = opts["entryTypes"] || opts[:entryTypes] || [opts["type"] || opts[:type]].compact
  @entry_types = Array(types).map(&:to_s)
  nil
end

#take_recordsObject Also known as: takeRecords



30
31
32
# File 'lib/dommy/performance_observer.rb', line 30

def take_records
  []
end