Class: Bluesky::ViewController
- Inherits:
-
Object
- Object
- Bluesky::ViewController
- Includes:
- ConditionHelper, DOMHelper, DSL, TryHelper, Clearwater::Component
- Defined in:
- lib/bluesky/view_controller.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#appearance ⇒ Object
Returns the value of attribute appearance.
-
#children ⇒ Object
Returns the value of attribute children.
-
#data ⇒ Object
Returns the value of attribute data.
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #add_child_view_controller(view_controller) ⇒ Object
- #begin_appearance_transition(appearing) ⇒ Object
- #did_move_to_parent_view_controller(view_controller) ⇒ Object
- #dismiss ⇒ Object
- #dispatch(target, action, *payload, &block) ⇒ Object
- #end_appearance_transition ⇒ Object
-
#force_update ⇒ Object
Dispatch methods.
- #force_update? ⇒ Boolean
-
#initialize(*_, children: [], parent: nil, data: {}) ⇒ ViewController
constructor
A new instance of ViewController.
- #navigation_controller ⇒ Object
- #notify(source, event, *payload) ⇒ Object
- #present(_view_controller) ⇒ Object
- #refresh(&block) ⇒ Object
- #remove_from_parent_view_controller ⇒ Object
- #render ⇒ Object
- #show(_view_controller) ⇒ Object
- #view ⇒ Object
- #view_did_appear ⇒ Object
- #view_did_disappear ⇒ Object
- #view_will_appear ⇒ Object
- #view_will_disappear ⇒ Object
-
#will_move_to_parent_view_controller(view_controller) ⇒ Object
Callbacks.
Methods included from DSL
Constructor Details
#initialize(*_, children: [], parent: nil, data: {}) ⇒ ViewController
Returns a new instance of ViewController.
40 41 42 43 44 45 46 47 |
# File 'lib/bluesky/view_controller.rb', line 40 def initialize(*_, children: [], parent: nil, data: {}) @children = children @parent = parent @data = data @appearance = :disappeared @force_update = false @delegate = self end |
Instance Attribute Details
#appearance ⇒ Object
Returns the value of attribute appearance.
38 39 40 |
# File 'lib/bluesky/view_controller.rb', line 38 def appearance @appearance end |
#children ⇒ Object
Returns the value of attribute children.
38 39 40 |
# File 'lib/bluesky/view_controller.rb', line 38 def children @children end |
#data ⇒ Object
Returns the value of attribute data.
38 39 40 |
# File 'lib/bluesky/view_controller.rb', line 38 def data @data end |
#parent ⇒ Object
Returns the value of attribute parent.
38 39 40 |
# File 'lib/bluesky/view_controller.rb', line 38 def parent @parent end |
Class Method Details
.attribute(name, *args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bluesky/view_controller.rb', line 15 def self.attribute(name, *args, &block) case args.length when 0 define_method(name) { data.fetch(name) } when 1 if args[0].respond_to?(:call) define_method(name) { data.fetch(name) { data.store(name, args[0].call) } } else define_method(name) { data.fetch(name, args[0]) } end else raise ArgumentError, %{ wrong number of arguments (#{args.length} for 1..2) } end define_method("#{name}=") { |value| data.store(name, value) } end |
.inherited(subclass) ⇒ Object
32 33 34 35 36 |
# File 'lib/bluesky/view_controller.rb', line 32 def self.inherited(subclass) define_method(subclass.name) do |**data| subclass.new(delegate: self, data: data) end end |
Instance Method Details
#add_child_view_controller(view_controller) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/bluesky/view_controller.rb', line 96 def add_child_view_controller(view_controller) view_controller.will_move_to_parent_view_controller(self) view_controller.remove_from_parent_view_controller children.push(view_controller) view_controller.parent = self view_controller.did_move_to_parent_view_controller(self) end |
#begin_appearance_transition(appearing) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bluesky/view_controller.rb', line 69 def begin_appearance_transition(appearing) if appearing return unless @appearance == :disappeared # raise "Invalid appearance #{@appearance} when appearing" if @appearance != :disappeared @appearance = :appearing view_will_appear() else return unless @appearance == :appeared # raise "Invalid appearance #{@appearance} when disappearing" if @appearance != :appeared @appearance = :disappearing view_will_disappear() end end |
#did_move_to_parent_view_controller(view_controller) ⇒ Object
131 132 |
# File 'lib/bluesky/view_controller.rb', line 131 def did_move_to_parent_view_controller(view_controller) end |
#dismiss ⇒ Object
117 118 119 |
# File 'lib/bluesky/view_controller.rb', line 117 def dismiss raise 'not implemented' end |
#dispatch(target, action, *payload, &block) ⇒ Object
61 62 63 |
# File 'lib/bluesky/view_controller.rb', line 61 def dispatch(target, action, *payload, &block) try(parent, :dispatch, target, action, *payload, &block) end |
#end_appearance_transition ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bluesky/view_controller.rb', line 83 def end_appearance_transition() case @appearance when :appearing @appearance = :appeared view_did_appear() when :disappearing @appearance = :disappeared view_did_disappear() else # raise "Invalid appearance #{@appearance} when transitioning" end end |
#force_update ⇒ Object
Dispatch methods
148 149 150 151 152 153 154 |
# File 'lib/bluesky/view_controller.rb', line 148 def force_update @force_update = true @parent.refresh do @force_update = false yield if block_given? end end |
#force_update? ⇒ Boolean
49 50 51 |
# File 'lib/bluesky/view_controller.rb', line 49 def force_update? @force_update end |
#navigation_controller ⇒ Object
121 122 123 124 |
# File 'lib/bluesky/view_controller.rb', line 121 def parent.is_a?() ? parent : try(parent, :navigation_controller) end |
#notify(source, event, *payload) ⇒ Object
65 66 67 |
# File 'lib/bluesky/view_controller.rb', line 65 def notify(source, event, *payload) try(parent, :notify, source, event, *payload) end |
#present(_view_controller) ⇒ Object
113 114 115 |
# File 'lib/bluesky/view_controller.rb', line 113 def present(_view_controller) raise 'not implemented' end |
#refresh(&block) ⇒ Object
156 157 158 |
# File 'lib/bluesky/view_controller.rb', line 156 def refresh(&block) @parent.refresh(&block) end |
#remove_from_parent_view_controller ⇒ Object
104 105 106 107 |
# File 'lib/bluesky/view_controller.rb', line 104 def remove_from_parent_view_controller return unless parent parent.children.delete(self) end |
#render ⇒ Object
57 58 59 |
# File 'lib/bluesky/view_controller.rb', line 57 def render view end |
#show(_view_controller) ⇒ Object
109 110 111 |
# File 'lib/bluesky/view_controller.rb', line 109 def show(_view_controller) raise 'not implemented' end |
#view ⇒ Object
53 54 55 |
# File 'lib/bluesky/view_controller.rb', line 53 def view nil end |
#view_did_appear ⇒ Object
137 138 |
# File 'lib/bluesky/view_controller.rb', line 137 def view_did_appear end |
#view_did_disappear ⇒ Object
143 144 |
# File 'lib/bluesky/view_controller.rb', line 143 def view_did_disappear end |
#view_will_appear ⇒ Object
134 135 |
# File 'lib/bluesky/view_controller.rb', line 134 def view_will_appear end |
#view_will_disappear ⇒ Object
140 141 |
# File 'lib/bluesky/view_controller.rb', line 140 def view_will_disappear end |
#will_move_to_parent_view_controller(view_controller) ⇒ Object
Callbacks
128 129 |
# File 'lib/bluesky/view_controller.rb', line 128 def will_move_to_parent_view_controller(view_controller) end |