Improved @delay and @interval, use globale storage.
This commit is contained in:
parent
e16b1959ec
commit
bae7552cda
2 changed files with 20 additions and 25 deletions
|
@ -204,53 +204,47 @@ class App.Controller extends Spine.Controller
|
||||||
|
|
||||||
|
|
||||||
clearDelay: (delay_id) =>
|
clearDelay: (delay_id) =>
|
||||||
# check global var
|
|
||||||
if !@_delayID
|
# get global delay ids
|
||||||
@_delayID = {}
|
current = @Config.get( delay_id, '_delayID' )
|
||||||
clearTimeout( @_delayID[delay_id] ) if @_delayID[delay_id]
|
return if !current
|
||||||
|
clearTimeout( current )
|
||||||
|
|
||||||
delay: (callback, timeout, delay_id) =>
|
delay: (callback, timeout, delay_id) =>
|
||||||
|
|
||||||
# clear auto save
|
|
||||||
@clearDelay( delay_id )
|
|
||||||
|
|
||||||
# request new data
|
# request new data
|
||||||
call = =>
|
call = =>
|
||||||
callback()
|
callback()
|
||||||
if delay_id
|
if delay_id
|
||||||
|
|
||||||
# check global var
|
# clear current delay_id
|
||||||
if !@_delayID
|
@clearDelay( delay_id )
|
||||||
@_delayID = {}
|
|
||||||
|
|
||||||
@_delayID[delay_id] = setTimeout( call, timeout )
|
new_id = setTimeout( call, timeout )
|
||||||
|
@Config.set( delay_id, new_id, '_delayID' )
|
||||||
else
|
else
|
||||||
setTimeout( call, timeout )
|
setTimeout( call, timeout )
|
||||||
|
|
||||||
clearInterval: (interval_id) =>
|
clearInterval: (interval_id) =>
|
||||||
# check global var
|
|
||||||
if !@_intervalID
|
|
||||||
@_intervalID = {}
|
|
||||||
|
|
||||||
clearInterval( @_intervalID[interval_id] ) if @_intervalID[interval_id]
|
# get global interval ids
|
||||||
|
current = @Config.get( interval_id, '_intervalID' )
|
||||||
|
return if !current
|
||||||
|
clearInterval( current )
|
||||||
|
|
||||||
interval: (callback, interval, interval_id) =>
|
interval: (callback, interval, interval_id) =>
|
||||||
|
|
||||||
# check global var
|
# clear current interval
|
||||||
if !@_intervalID
|
@clearInterval( interval_id )
|
||||||
@_intervalID = {}
|
|
||||||
|
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
# auto save
|
every = (ms, cb) =>
|
||||||
every = (ms, cb) -> setInterval cb, ms
|
setInterval cb, ms
|
||||||
|
|
||||||
# clear auto save
|
|
||||||
@clearInterval( @_intervalID[interval_id] )
|
|
||||||
|
|
||||||
# request new data
|
# request new data
|
||||||
@_intervalID[interval_id] = every interval, () =>
|
new_id = every( interval, callback )
|
||||||
callback()
|
@Config.set( interval_id, new_id, '_intervalID' )
|
||||||
|
|
||||||
userPopups: (position = 'right') ->
|
userPopups: (position = 'right') ->
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class _Singleton
|
||||||
get: ( key, group ) ->
|
get: ( key, group ) ->
|
||||||
if group
|
if group
|
||||||
return undefined if !group of @config
|
return undefined if !group of @config
|
||||||
|
return undefined if @config[group] is undefined
|
||||||
return @config[group][key]
|
return @config[group][key]
|
||||||
return @config[key]
|
return @config[key]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue