Class: Preact::OptionHooks

Inherits:
Object show all
Defined in:
lib/preact/option_hooks.rb

Class Method Summary collapse

Class Method Details

.debounce_rendering(&block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/preact/option_hooks.rb', line 4

def debounce_rendering(&block)
  %x{
    const old_hook = Opal.global.Preact.options.debounceRendering;
    Opal.global.Preact.options.debounceRendering = function(callback) {
      #{block.call};
      if (old_hook) {
        old_hook(callback);
      }
    }
  }
  nil
end

.diffed(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/preact/option_hooks.rb', line 17

def diffed(&block)
  # TODO wrap vnode
  %x{
    const old_hook = Opal.global.Preact.options.diffed;
    Opal.global.Preact.options.diffed = function(vnode) {
      #{block.call(`vnode`)};
      if (old_hook) {
        old_hook(vnode);
      }
    }
  }
  nil
end

.event(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/preact/option_hooks.rb', line 31

def event(&block)
  %x{
    const old_hook = Opal.global.Preact.options.event;
    Opal.global.Preact.options.event = function(event) {
      ruby_event = #{Browser::Event.new(`event`)}
      ruby_event = #{block.call(`ruby_event`)};
      return ruby_event.native;
    }
  }
  nil
end

.request_animation_frame(&block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/preact/option_hooks.rb', line 43

def request_animation_frame(&block)
  %x{
    const old_hook = Opal.global.Preact.options.requestAnimationFrame;
    Opal.global.Preact.options.requestAnimationFrame = function(callback) {
      #{block.call};
      if (old_hook) {
        old_hook(callback);
      }
    }
  }
  nil
end

.unmount(&block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/preact/option_hooks.rb', line 56

def unmount(&block)
  # TODO wrap vnode
  %x{
    const old_hook = Opal.global.Preact.options.unmount;
    Opal.global.Preact.options.unmount = function(vnode) {
      #{block.call(`vnode`)};
      if (old_hook) {
        old_hook(vnode);
      }
    }
  }
  nil
end

.use_debug_value(&block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/preact/option_hooks.rb', line 70

def use_debug_value(&block)
  %x{
    const old_hook = Opal.global.Preact.options.useDebugValue;
    Opal.global.Preact.options.useDebugValue = function(value) {
      #{block.call(`value`)};
      if (old_hook) {
        old_hook(value);
      }
    }
  }
  nil
end

.vnode(&block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/preact/option_hooks.rb', line 83

def vnode(&block)
  %x{
    const old_hook = Opal.global.Preact.options.unmount;
    Opal.global.Preact.options.unmount = function(vnode) {
      #{block.call(`vnode`)};
      if (old_hook) {
        old_hook(vnode);
      }
    }
  }
  nil
end