Skip to content

Commit c764599

Browse files
Merge pull request #62 from josemarluedke/fix-component-destroy-error
Fix component destroy error
2 parents 2558f24 + 845ab1d commit c764599

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

addon/components/stripe-element.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,47 @@ export default Component.extend({
6868

6969
setEventListeners() {
7070
let stripeElement = get(this, 'stripeElement');
71-
stripeElement.on('ready', (event) => this.ready(stripeElement, event));
72-
stripeElement.on('blur', (event) => this.blur(stripeElement, event));
73-
stripeElement.on('focus', (event) => this.focus(stripeElement, event));
71+
72+
stripeElement.on('ready', (event) => {
73+
this._invokeAction('ready', stripeElement, event)
74+
});
75+
76+
stripeElement.on('blur', (event) => {
77+
this._invokeAction('blur', stripeElement, event)
78+
});
79+
80+
stripeElement.on('focus', (event) => {
81+
this._invokeAction('focus', stripeElement, event)
82+
});
83+
7484
stripeElement.on('change', (...args) => {
85+
if (this.isDestroying || this.isDestroyed) {
86+
return;
87+
}
88+
7589
let [{ complete, error: stripeError }] = args;
7690
this.change(stripeElement, ...args);
7791

7892
if (complete) {
79-
this.complete(stripeElement);
93+
this._invokeAction('complete', stripeElement)
8094
} else if (stripeError) {
81-
this.error(stripeError);
95+
this._invokeAction('error', stripeError)
8296
}
8397

8498
set(this, 'stripeError', stripeError);
8599
});
86100
},
87101

102+
_invokeAction(method, ...args) {
103+
if (this.isDestroying || this.isDestroyed) {
104+
return;
105+
}
106+
107+
if (typeof this[method] === 'function') {
108+
this[method](...args)
109+
}
110+
},
111+
88112
ready() { },
89113
blur() { },
90114
focus() { },

0 commit comments

Comments
 (0)