Class: Wee::Component

Inherits:
Presenter show all
Includes:
CallAnswerMixin, DecorationMixin
Defined in:
lib/wee/component.rb

Overview

The base class of all components. You should at least overwrite method #render in your own subclasses.

Constant Summary collapse

NO_CHILDREN =
[].freeze

Instance Method Summary collapse

Methods included from DecorationMixin

#add_decoration, #decoration, #decoration=, #each_decoration, #remove_decoration, #remove_decoration_if

Methods inherited from Presenter

#render_on, #renderer_class

Constructor Details

#initializeComponent

Initializes a newly created component.



16
17
# File 'lib/wee/component.rb', line 16

def initialize
end

Instance Method Details

#childrenObject

Return all child components.

OVERWRITE this method and return all child components collected in an array.



69
70
71
# File 'lib/wee/component.rb', line 69

def children
  return NO_CHILDREN
end

#process_callbacks(callbacks) ⇒ Object

Process and invoke all callbacks specified for this component and all of it’s child components.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/wee/component.rb', line 77

def process_callbacks(callbacks)
  callbacks.input_callbacks.each_triggered(self) do |callback, value|
    callback.call(value)
  end

  # process callbacks of all children
  for child in self.children
    child.decoration.process_callbacks(callbacks)
  end

  callbacks.action_callbacks.each_triggered(self) do |callback, value|
    callback.call
    session.send_response(nil) # prematurely end callback processing
  end
end

#render(r) ⇒ Object

This method renders the content of the component.

OVERWRITE this method in your own component classes to implement the view. By default this method does nothing!

r

An instance of class renderer_class()



28
29
# File 'lib/wee/component.rb', line 28

def render(r)
end

#state(s) ⇒ Object

Take snapshots of objects that should correctly be backtracked.

Backtracking means that you can go back in time of the components’ state. Therefore it is neccessary to take snapshots of those objects that want to participate in backtracking. Taking snapshots of the whole component tree would be too expensive and unflexible. Note that methods take_snapshot and restore_snapshot are called for those objects to take the snapshot (they behave like marshal_dump and marshal_load). Overwrite them if you want to define special behaviour.

By default only the decoration chain is backtracked. This is required to correctly backtrack called components. To disable backtracking of the decorations, change method Component#state_decoration to a no-operation:

def state_decoration(s)
  # nothing here
end
s

An object of class State



55
56
57
58
59
60
# File 'lib/wee/component.rb', line 55

def state(s)
  state_decoration(s)
  for child in self.children
    child.decoration.state(s)
  end
end