Created
February 11, 2019 15:37
-
-
Save chrismllr/e6ab8ee122cebe4fc86e0d2a24b40972 to your computer and use it in GitHub Desktop.
Confirm action service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Service from '@ember/service'; | |
import { setProperties } from '@ember/object'; | |
import { defer } from 'rsvp'; | |
export default Service.extend({ | |
showPrompt: false, | |
title: null, | |
message: null, | |
_deferred: null, | |
ask({ title, message }) { | |
setProperties(this, { | |
_deferred: defer(), | |
showPrompt: true, | |
title, | |
message | |
}); | |
return this._deferred.promise; | |
}, | |
actions: { | |
confirm() { | |
this._deferred.resolve(true); | |
setProperties(this, { | |
showPrompt: false, | |
_deferred: null | |
}); | |
}, | |
cancel() { | |
this._deferred.resolve(false); | |
setProperties(this, { | |
showPrompt: false, | |
_deferred: null | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment