Trying to clean up the promises patterns.
This commit is contained in:
parent
334fb0efff
commit
39bd7ee63b
|
@ -310,17 +310,18 @@ Note that in Coffeescript, the [[=>]] operator completely replaces the
|
||||||
|
|
||||||
<<base view>>=
|
<<base view>>=
|
||||||
hide: () ->
|
hide: () ->
|
||||||
|
dfd = $.Deferred()
|
||||||
if not @el.is(':visible')
|
if not @el.is(':visible')
|
||||||
return null
|
return dfd.resolve()
|
||||||
promise = $.Deferred (dfd) => @el.fadeOut('fast', dfd.resolve)
|
@el.fadeOut('fast', () -> dfd.resolve())
|
||||||
promise.promise()
|
dfd.promise()
|
||||||
|
|
||||||
show: () ->
|
show: () ->
|
||||||
|
dfd = $.Deferred()
|
||||||
if @el.is(':visible')
|
if @el.is(':visible')
|
||||||
return
|
return dfd.resolve()
|
||||||
|
@el.fadeIn('fast', () -> dfd.resolve())
|
||||||
promise = $.Deferred (dfd) => @el.fadeIn('fast', dfd.resolve)
|
dfd.promise()
|
||||||
promise.promise()
|
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|
||||||
|
@ -661,12 +662,14 @@ method returns only an array of deferreds.
|
||||||
@
|
@
|
||||||
|
|
||||||
Showing the product list view is basically hiding everything, then
|
Showing the product list view is basically hiding everything, then
|
||||||
showing the index:
|
showing the index. The function [[$$.when]] takes arguments of what to
|
||||||
|
wait for; to make it take an array of arguments, you use the
|
||||||
|
[[.apply()]] method.
|
||||||
|
|
||||||
<<router>>=
|
<<router>>=
|
||||||
index: () ->
|
index: () ->
|
||||||
view = @views['_index']
|
view = @views['_index']
|
||||||
$.when(@hideAllViews()).then(() -> view.show())
|
$.when.apply($, @hideAllViews()).then(() -> view.show())
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue