UNPKG

ember-gestures

Version:

TouchAction and Gesture support for Ember Applications

47 lines (35 loc) 1.06 kB
import { get, observer, computed } from '@ember/object'; import GestureArea from './gesture-element'; /**! * * Provides the ability to easily build a * gesture-ful async-button implementation * */ export default GestureArea.extend({ classNameBindings: ['actionState'], actionState: 'default', isPending: computed('actionState', function() { return this.get('actionState') === 'pending'; }), _getParams: function(actionName) { let actionArguments = this._super(actionName); let callbackHandler = (promise) => { this.set('promise', promise); this.set('actionState', 'pending'); }; actionArguments.splice(1, 0, callbackHandler); return actionArguments; }, __observePromiseState: observer('promise', function promiseTheComponentState() { get(this, 'promise') .then(() => { if (!this.isDestroyed) { this.set('actionState', 'fulfilled'); }}) .catch(() => { if (!this.isDestroyed) { this.set('actionState', 'rejected'); }}); }) });