Skip to content

Commit

Permalink
public: Prepare Dialog.doOperation for Backend ops
Browse files Browse the repository at this point in the history
Now that API success and error handling messages will be encapsulated
within `Backend` functions, we can make `Dialog.doOperation` much more
lightweight.
  • Loading branch information
mbland committed Jul 31, 2017
1 parent 6e75273 commit 7f9602e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 5 additions & 6 deletions public/app.js
Expand Up @@ -425,18 +425,17 @@
}
}

cl.Dialog.prototype.doOperation = function(op, result, linkInfo, messages) {
cl.Dialog.prototype.doOperation = function(op, result) {
var dialog = this

return cl.flashResult(result,
op.then(function() {
op.then(function(message) {
dialog.close()
return messages.success
return message
})
.catch(function(xhrOrErr) {
.catch(function(err) {
dialog.close()
return Promise.reject(cl.apiErrorMessage(xhrOrErr, linkInfo,
messages.failure))
return Promise.reject(err)
})
)
}
Expand Down
12 changes: 4 additions & 8 deletions public/tests/tests.js
Expand Up @@ -1019,11 +1019,9 @@ describe('Custom Links', function() {

it('closes the dialog and flashes the result on success', function() {
return dialog
.doOperation(Promise.resolve('Success!'), element,
cl.createLinkInfo('foo'),
{ success: 'All good!', failure: 'Uh-oh...' })
.doOperation(Promise.resolve('Success!'), element)
.then(function() {
element.textContent.should.equal('All good!')
element.textContent.should.equal('Success!')
expect(element.children[0]).to.not.be.undefined
element.children[0].className.should.equal('result success')
expect(dialog.element.parentNode).to.be.null
Expand All @@ -1032,11 +1030,9 @@ describe('Custom Links', function() {

it('closes the dialog and flashes the result on failure', function() {
return dialog
.doOperation(Promise.reject('Failure!'), element,
cl.createLinkInfo('foo'),
{ success: 'All good!', failure: 'Uh-oh' })
.doOperation(Promise.reject('Failure!'), element)
.then(function() {
element.textContent.should.equal('Uh-oh: Failure!')
element.textContent.should.equal('Failure!')
expect(element.children[0]).to.not.be.undefined
element.children[0].className.should.equal('result failure')
expect(dialog.element.parentNode).to.be.null
Expand Down

0 comments on commit 7f9602e

Please sign in to comment.