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.
This commit is contained in:
Ben Gotow 2015-07-17 13:25:54 -07:00
parent cb8427f447
commit 728135e07d

View file

@ -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