class Bluesky::Application
The application entry point
Attributes
delegate[RW]
Receives all notifications
root_view_controller[RW]
Top level ViewController
Public Class Methods
new()
click to toggle source
# File lib/bluesky/application.rb, line 15 def initialize @dispatch_queue = [] @debug = false end
Public Instance Methods
debug!()
click to toggle source
Turns on debug logging
# File lib/bluesky/application.rb, line 25 def debug! @debug = true self end
debug?()
click to toggle source
# File lib/bluesky/application.rb, line 20 def debug? @debug end
dispatch(target, action, *payload, &block)
click to toggle source
Dispatches an action on target
Attributes:
target: (Object) The object that receives the send action action (Symbol) The method symbol on target payload: (Array) The arguments passed to send if any block: (Block) Optional block that will be passed as argument to send
# File lib/bluesky/application.rb, line 37 def dispatch(target, action, *payload, &block) promise = Promise.new notify(self, :dispatch_requested, target, action, *payload) @dispatch_queue << lambda do begin result = target.send(action, *payload, &block) promise.resolve(result).then { refresh } notify(self, :dispatch_resolved, target, action, *payload, result) rescue => err promise.reject(err) notify(self, :dispatch_rejected, target, action, *payload, err) end end defer { process_dispatch_queue } promise end
notify(source, event, *payload)
click to toggle source
Notifies the delegate about an event
Attributes:
source: (Object) The object that send the event event: (Symbol) The event symbol payload: (Array) Additional arguments to pass along
# File lib/bluesky/application.rb, line 61 def notify(source, event, *payload) try(@delegate, source, event, *payload) if debug? message = "#{event} #{payload}" if RUBY_ENGINE == 'opal' `console.log(message)` else puts message end end end
refresh(&block)
click to toggle source
Refreshes (runs render) on the root_view_controller
and invokes the block (if any) when the render is complete.
# File lib/bluesky/application.rb, line 75 def refresh(&block) promise = Promise.new @clearwater.call { promise.resolve } block ? promise.then(&block) : promise end
run()
click to toggle source
Does the required wiring and runs the initial render
# File lib/bluesky/application.rb, line 82 def run raise 'root_view_controller must be defined in Application' unless root_view_controller PureComponent.install_hooks(debug?) root_view_controller.parent = self router = RUBY_ENGINE != 'opal' ? Clearwater::Router.new(location: 'http://localhost:9292/') : Clearwater::Router.new @clearwater = Clearwater::Application.new( component: root_view_controller, router: router ) @clearwater.debug! if debug? root_view_controller.begin_appearance_transition(true) refresh { root_view_controller.end_appearance_transition() } self end
Private Instance Methods
process_dispatch_queue()
click to toggle source
Processes queued dispatches
# File lib/bluesky/application.rb, line 102 def process_dispatch_queue return if @dispatch_queue.empty? @dispatch_queue.delete_if do |task| task.call true end end