Mailspring/spec
Ben Gotow 45bb16561f feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks
Summary:
This diff does a couple things:

- Undo redo with a new undo/redo store that maintains it's own queue of undo/redo tasks. This queue is separate from the TaskQueue because not all tasks should be considered for undo history! Right now just the AddRemoveTagsTask is undoable.

- NylasAPI.makeRequest now returns a promise which resolves with the result or rejects with an error. For things that still need them, there's still `success` and `error` callbacks. I also added `started:(req) ->` which allows you to get the underlying request.

- Aborting a NylasAPI request now makes it call it's error callback / promise reject.

- You can now run code after perform local has completed using this syntax:

```
    task = new AddRemoveTagsTask(focused, ['archive'], ['inbox'])
    task.waitForPerformLocal().then ->
      Actions.setFocus(collection: 'thread', item: nextFocus)
      Actions.setCursorPosition(collection: 'thread', item: nextKeyboard)
    Actions.queueTask(task)
```

- In specs, you can now use `advanceClock` to get through a Promise.then/catch/finally. Turns out it was using something low level and not using setTimeout(0).

- The TaskQueue uses promises better and defers a lot of the complexity around queueState for performLocal/performRemote to a task subclass called APITask. APITask implements "perform" and breaks it into "performLocal" and "performRemote".

- All tasks either resolve or reject. They're always removed from the queue, unless they resolve with Task.Status.Retry, which means they internally did a .catch (err) => Promise.resolve(Task.Status.Retry) and they want to be run again later.

- API tasks retry until they succeed or receive a NylasAPI.PermanentErrorCode (400,404,500), in which case they revert and finish.

- The AddRemoveTags Task can now take more than one thread! This is super cool because you can undo/redo a bulk action and also because we'll probably have a bulk tag modification API endpoint soon.

Getting undo / redo working revealed that the thread versioning system we built isn't working because the server was incrementing things by more than 1 at a time. Now we count the number of unresolved "optimistic" changes we've made to a given model, and only accept the server's version of it once the number of optimistic changes is back at zero.

Known Issues:

- AddRemoveTagsTasks aren't dependent on each other, so if you (undo/redo x lots) and then come back online, all the tasks try to add / remove all the tags at the same time. To fix this we can either allow the tasks to be merged together into a minimal set or make them block on each other.

- When Offline, you still get errors in the console for GET requests. Need to catch these and display an offline status bar.

- The metadata tasks haven't been updated yet to the new API. Wanted to get it reviewed first!

Test Plan: All the tests still pass!

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D1694
2015-07-07 13:38:53 -04:00
..
fixtures add(specs): +101 specs and 403 assertions from Atom 2015-06-02 19:51:00 -07:00
6to5-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
atom-reporter.coffee feat(logging): Developer bar, verbose logging to logstash, Electron 0.26.0 2015-05-19 17:02:46 -07:00
atom-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
command-installer-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
command-registry-spec.coffee refactor(utils): switch to regular underscore 2015-05-19 16:06:59 -07:00
config-spec.coffee fix(naming): Move atom/inbox/nilas refs to Nylas 2015-05-15 11:07:28 -07:00
context-menu-manager-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
deserializer-manager-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
jasmine-helper.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
language-mode-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
notification-manager-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
notification-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
space-pen-extensions-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
spec-bootstrap.coffee fix(asar): Support ASAR, and running of specs in prod builds 2015-05-21 14:41:30 -07:00
spec-helper-platform.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
spec-helper.coffee feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks 2015-07-07 13:38:53 -04:00
spec-suite.coffee refactor(utils): switch to regular underscore 2015-05-19 16:06:59 -07:00
squirrel-update-spec.coffee fix(drafts): Various improvements and fixes to drafts, draft state management 2015-02-03 16:24:31 -08:00
time-reporter.coffee refactor(utils): switch to regular underscore 2015-05-19 16:06:59 -07:00
window-spec.coffee fix(mailto): Handle mailto on application launch, populate NamespaceStore synchronously 2015-05-21 18:08:29 -07:00
workspace-spec.coffee refactor(utils): switch to regular underscore 2015-05-19 16:06:59 -07:00