coffee/watch.coffee in gon-6.1.0 vs coffee/watch.coffee in gon-6.2.0
- old
+ new
@@ -1,28 +1,35 @@
gon._timers = {}
-gon.watch = (name, possibleOptions, possibleCallback) ->
+gon.watch = (name, possibleOptions, possibleCallback, possibleErrorCallback) ->
return unless $?
if typeof possibleOptions == 'object'
options = {}
for key, value of gon.watchedVariables[name]
options[key] = value
for key, value of possibleOptions
options[key] = value
callback = possibleCallback
+ errorCallback = possibleErrorCallback
else
options = gon.watchedVariables[name]
callback = possibleOptions
+ errorCallback = possibleCallback
+
performAjax = ->
xhr = $.ajax
type: options.type || 'GET'
url: options.url
data:
_method: options.method
gon_return_variable: true
gon_watched_variable: name
- xhr.done(callback)
+
+ if errorCallback
+ xhr.done(callback).fail(errorCallback);
+ else
+ xhr.done(callback)
if options.interval
timer = setInterval(performAjax, options.interval)
gon._timers[name] ?= []
return gon._timers[name].push