From 728135e07d40a7db0371406f2abf546f14f0205a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 17 Jul 2015 13:25:54 -0700 Subject: [PATCH] fix(close): Closing a draft always works on the first try We were accidentally firing atom.close() in the same tick that we returned false and canceled the close. --- src/flux/stores/draft-store.coffee | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index 8eea23d58..7958ab51e 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -159,13 +159,15 @@ class DraftStore if session.draft()?.pristine Actions.queueTask(new DestroyDraftTask(session.draftLocalId)) else - promise = session.changes.commit() - promises.push(promise) unless promise.isFulfilled() + promises.push(session.changes.commit()) if promises.length > 0 + # Important: There are some scenarios where all the promises resolve instantly. + # Firing atom.close() does nothing if called within an existing beforeUnload + # handler, so we need to always defer by one tick before re-firing close. Promise.settle(promises).then => @_draftSessions = {} - atom.close() + _.defer -> atom.close() # Stop and wait before closing return false