Sha256: 994d62a251a4b81a37daa43041b1c9cc64c4a75c1f252b18c16e294ffab548d6

Contents?: true

Size: 1013 Bytes

Versions: 4

Compression:

Stored size: 1013 Bytes

Contents

#
# Comfortable and clever wrappers for timeouts management
#
# @mixin
#
Joosy.Modules.TimeManager =
  
  #
  # Registeres timeout for current object
  #
  # @param [Integer] timeout          Miliseconds to wait
  # @param [Function] action          Action to run on timeout
  #
  setTimeout: (timeout, action) ->
    @__timeouts ||= []

    timer = window.setTimeout (=> action()), timeout
    @__timeouts.push timer

    timer

  #
  # Registeres interval for current object
  #
  # @param [Integer] delay            Miliseconds between runs
  # @param [Function] action          Action to run
  #
  setInterval: (delay, action) ->
    @__intervals ||= []

    timer = window.setInterval (=> action()), delay
    @__intervals.push timer

    timer

  #
  # Drops all registered timeouts and intervals for this object
  #
  __clearTime: ->
    if @__intervals
      for entry in @__intervals
        window.clearInterval entry

    if @__timeouts
      for entry in @__timeouts
        window.clearTimeout entry

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
joosy-1.0.0.RC4 app/assets/javascripts/joosy/core/modules/time_manager.js.coffee
joosy-1.0.0.RC3 app/assets/javascripts/joosy/core/modules/time_manager.js.coffee
joosy-1.0.0.RC2 app/assets/javascripts/joosy/core/modules/time_manager.js.coffee
joosy-1.0.0.RC1 app/assets/javascripts/joosy/core/modules/time_manager.js.coffee