lib/bowline/binders.rb in bowline-0.6.3 vs lib/bowline/binders.rb in bowline-0.9.1
- old
+ new
@@ -53,10 +53,21 @@
# <script>
# $('#users').items(10).invoke('charge!');
# </script>
#
# For more documentation on Bowline's JavaScript API, see bowline.js
+
+ def active(binder = nil) #:nodoc:
+ @active ||= []
+ if binder
+ @active << binder
+ @active.uniq!
+ end
+ @active
+ end
+ module_function :active
+
class Base
extend Bowline::Watcher::Base
extend Bowline::Desktop::Bridge::ClassMethods
js_expose
@@ -64,16 +75,16 @@
protected
def async(*methods)
if block_given?
Thread.new(callback_proc) do |proc|
begin
- self.callback_proc = proc
- yield
- rescue => e
- Bowline::Logging.log_error(e)
+ self.callback_proc = proc
+ yield
+ rescue => e
+ Bowline::Logging.log_error(e)
+ end
end
- end
else
methods.each do |method|
class_eval(<<-EOS, __FILE__, __LINE__)
def #{method}_with_async(*args, &block)
async { #{method}_without_async(*args, &block) }
@@ -87,11 +98,11 @@
extend Async
include Async
class << self; extend Async; end
- class << self
+ class << self
def callback_proc(proc = nil) #:nodoc:
Thread.current[:callback] = proc if proc
Thread.current[:callback]
end
alias_method :callback_proc=, :callback_proc
@@ -113,20 +124,28 @@
def instance_invoke(id, method, *args) #:nodoc:
self.new(id).send(method, *args)
end
# An array of window currently bound.
- def windows
+ def windows(window = nil)
@windows ||= []
+ if window
+ @windows << window
+ @windows.uniq!
+ end
+ @windows
end
def setup(window) #:nodoc:
- self.windows << window
- self.windows.uniq!
- if initial_items = initial
- self.items = initial_items
- end
+ Binders.active(self)
+ windows(window)
+ populate
callback(true)
+ end
+
+ # Populate initial items
+ def populate(items = initial)
+ self.items = items if items
end
# Called by a window's JavaScript whenever that window is bound to this Binder.
# This method populates the window's HTML with all bound class' records.
# Override this if you don't want to send all the class' records to the window.
\ No newline at end of file