I'm using Iced coffescript with upshot js when I am refreshing multiple data sources. The refresh method has TWo call backs one for success and one for error and I want to wait for each call to make either callback.
I can't see how to do this with idced coffescript without making an additional function. My question is - is there a more elegant way that I can defer to one of multiple callbacks?
This is the code I have currently:
refreshMe = (key, value, result) =>
value.refresh(
(success)=>
result success
,
(fail, reason, error)=>
result undefined, fail
)
@refresh = () =>
success={}
fail={}
await
for key, value of @dataSources
refreshMe key, value, defer success[key], fail[key]
This is the only way I have found to do it too. I'm using it in Backbone and wrap (for example) a model's @save function with an @icedSave:
# An IcedCoffeescript friendly version of save
icedSave: (callback) ->
@save {},
success: (model, response) -> callback(true, model, response)
error: (model, response) -> callback(false, model, response)