Skip to content

Commit

Permalink
Add possibleErrorCallback to watch params
Browse files Browse the repository at this point in the history
Fixes gazay#215
  • Loading branch information
etagwerker committed Nov 11, 2016
1 parent 131aeaa commit afe2a1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions coffee/watch.coffee
@@ -1,6 +1,6 @@
gon._timers = {}

gon.watch = (name, possibleOptions, possibleCallback) ->
gon.watch = (name, possibleOptions, possibleCallback, possibleErrorCallback) ->
return unless $?

if typeof possibleOptions == 'object'
Expand All @@ -10,9 +10,12 @@ gon.watch = (name, possibleOptions, possibleCallback) ->
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'
Expand All @@ -21,7 +24,11 @@ gon.watch = (name, possibleOptions, possibleCallback) ->
_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)
Expand Down
16 changes: 11 additions & 5 deletions js/watch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afe2a1a

Please sign in to comment.