Created
February 23, 2012 13:27
-
-
Save 5509/1892781 to your computer and use it in GitHub Desktop.
Repeat func
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Repeat func | |
# | |
# @param {} | |
# { | |
# interval: 50, | |
# func: -> | |
# console.log 'func' | |
# } | |
# | |
# or | |
# | |
# { | |
# interval: 50, | |
# func: { | |
# key1: -> | |
# console.log 'key1' | |
# key2: -> | |
# console.log 'key2' | |
# . | |
# . | |
# . | |
# } | |
# } | |
utils.repeat = class Repeat | |
constructor: (conf) -> | |
if !(@ instanceof Repeat) | |
return new Repeat(conf) | |
return @init(conf) | |
init: (conf) -> | |
@disable = no | |
@running = no | |
@conf = | |
interval: 50, | |
func: -> | |
for c of conf | |
@conf[c] = conf[c] | |
return | |
run: (func_key) -> | |
@disable = no | |
@running = yes | |
conf = @conf | |
do => | |
if @disable | |
return | |
if typeof conf.func is 'function' | |
conf.func() | |
else if typeof conf.func is 'object' | |
conf.func[func_key]() | |
setTimeout(arguments.callee, conf.interval) | |
return | |
return | |
stop: -> | |
@disable = yes | |
@running = no | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment