lib/vedeu/support/event.rb in vedeu-0.1.17 vs lib/vedeu/support/event.rb in vedeu-0.1.18
- old
+ new
@@ -25,75 +25,103 @@
private
attr_reader :closure
attr_accessor :deadline, :executed_at, :now
+ # @api private
+ # @return []
def execute(*args)
reset_deadline
set_executed
reset_time
closure.call(*args)
end
+ # @api private
+ # @return [TrueClass|FalseClass]
def throttling?
set_time
options[:delay] > 0
end
+ # @api private
+ # @return [TrueClass|FalseClass]
def debouncing?
set_time
set_deadline unless has_deadline?
options[:debounce] > 0
end
+ # @api private
+ # @return [Float]
def elapsed_time
now - @executed_at
end
+ # @api private
+ # @return [Float]
def set_executed
@executed_at = now
end
+ # @api private
+ # @return [Float]
def set_time
@now = Time.now.to_f
end
+ # @api private
+ # @return [Fixnum]
def reset_time
@now = 0
end
+ # @api private
+ # @return [TrueClass|FalseClass]
def has_deadline?
@deadline > 0
end
+ # @api private
+ # @return [Fixnum]
def reset_deadline
@deadline = 0
end
+ # @api private
+ # @return [NilClass]
def set_deadline
@deadline = now + debounce
nil
end
+ # @api private
+ # @return [Fixnum|Float]
def debounce
options[:debounce]
end
+ # @api private
+ # @return [Fixnum|Float]
def delay
options[:delay]
end
+ # @api private
+ # @return [Hash]
def options
defaults.merge!(@options)
end
+ # @api private
+ # @return [Hash]
def defaults
{
delay: 0,
debounce: 0
}