Class: Wee::Component
- 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.
Instance Attribute Summary
Attributes included from DecorationMixin
Instance Method Summary collapse
-
#backtrack(state) ⇒ Object
Take snapshots of objects that should correctly be backtracked.
-
#initialize ⇒ Component
constructor
Initializes a newly created component.
-
#process_callbacks(callbacks) ⇒ Object
Process and invoke all callbacks specified for this component and all of it’s child components.
-
#render(r) ⇒ Object
This method renders the content of the component.
Methods included from DecorationMixin
#add_decoration, #each_decoration, #remove_decoration, #remove_decoration_if
Methods inherited from Presenter
Constructor Details
#initialize ⇒ Component
Initializes a newly created component.
Call this method from your own components’ initialize method using super, before setting up anything else!
19 20 21 22 |
# File 'lib/wee/component.rb', line 19 def initialize() # :notnew: @decoration = self @children = nil end |
Instance Method Details
#backtrack(state) ⇒ 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.
For example if you dynamically add children to your component, you might want to backtrack the children array:
def backtrack(state)
super
backtrack_children(state)
end
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#backtrack_decoration to a no-operation:
def backtrack_decoration(state)
# nothing here
end
state-
An object of class State
88 89 90 91 92 93 |
# File 'lib/wee/component.rb', line 88 def backtrack(state) backtrack_decoration(state) each_child do |child| child.decoration.backtrack(state) end end |
#process_callbacks(callbacks) ⇒ Object
Process and invoke all callbacks specified for this component and all of it’s child components.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wee/component.rb', line 40 def process_callbacks(callbacks) callbacks.input_callbacks.each_triggered(self) do |callback, value| callback.call(value) end # process callbacks of all children each_child do |child| 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()
33 34 |
# File 'lib/wee/component.rb', line 33 def render(r) end |