From 39bd7ee63b1bf5468a74dbe57471663857845767 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Fri, 15 Apr 2016 17:36:32 -0700 Subject: [PATCH] Trying to clean up the promises patterns. --- src/backbonestore.nw | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backbonestore.nw b/src/backbonestore.nw index 3c46726..24a2023 100644 --- a/src/backbonestore.nw +++ b/src/backbonestore.nw @@ -310,17 +310,18 @@ Note that in Coffeescript, the [[=>]] operator completely replaces the <>= hide: () -> + dfd = $.Deferred() if not @el.is(':visible') - return null - promise = $.Deferred (dfd) => @el.fadeOut('fast', dfd.resolve) - promise.promise() + return dfd.resolve() + @el.fadeOut('fast', () -> dfd.resolve()) + dfd.promise() show: () -> + dfd = $.Deferred() if @el.is(':visible') - return - - promise = $.Deferred (dfd) => @el.fadeIn('fast', dfd.resolve) - promise.promise() + return dfd.resolve() + @el.fadeIn('fast', () -> dfd.resolve()) + dfd.promise() @ @@ -661,12 +662,14 @@ method returns only an array of deferreds. @ 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. <>= index: () -> view = @views['_index'] - $.when(@hideAllViews()).then(() -> view.show()) + $.when.apply($, @hideAllViews()).then(() -> view.show()) @