src/plugins/events.coffee in luca-0.9.4 vs src/plugins/events.coffee in luca-0.9.6
- old
+ new
@@ -19,14 +19,15 @@
unless _.isFunction(fn)
throw "Must pass a function or a string representing one"
if wrapWithUnderscore is true
- @fn = ()=>
+ @fn = _.bind ()->
_.defer(fn)
+ , @object
else
- @fn = fn
+ @fn = _.bind(fn,@object)
@
# until accepts an object to bind to, and a trigger to bind with
# if you just pass a trigger, the object getting bound to
@@ -39,10 +40,11 @@
watch.once(trigger, @fn)
@object
Luca.Events =
+
defer: (operation, wrapWithUnderscore=true)->
new DeferredBindingProxy(@, operation, wrapWithUnderscore)
once: (trigger, callback, context)->
context ||= @
@@ -50,5 +52,31 @@
onceFn = ()->
callback.apply(context, arguments)
@unbind(trigger, onceFn)
@bind trigger, onceFn
+
+
+Luca.EventsExt =
+ waitUntil:(trigger, context)->
+ @waitFor.call(@, trigger, context )
+
+ waitFor: (trigger, context)->
+ self = @
+ proxy =
+ on:(target)->
+ target.waitFor.call(target,trigger,context)
+ and:(runList...)->
+ for fn in runList
+ fn = if _.isFunction(fn) then fn else self[fn]
+ self.once(trigger, fn, context)
+ andThen: ()->
+ self.and.apply(self, arguments)
+
+ relayEvent: (trigger)->
+ on: (components...)=>
+ to: (targets...)=>
+ for target in targets
+ for component in components
+ component.on trigger, (args...)=>
+ args.unshift(trigger)
+ target.trigger.apply(target,args)