-
Notifications
You must be signed in to change notification settings - Fork 123
Destory the element and reset the Stripe object #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for doing this! This is the recommended way to destroy components in Vue.
Any updates on this @nkoehring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonlfunk thank you for your contribution! Could you also update package.json version to 0.2.3
?
export function destroy() { | ||
Stripe.instance = null; | ||
Stripe.elements = null; | ||
Stripe.createToken = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove semicolons?
@@ -26,6 +26,8 @@ export default { | |||
|
|||
beforeDestroy () { | |||
this._element.unmount() | |||
this._element.destroy() | |||
destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove semicolon
Is this supposed to work when hot reloading? |
This is the solution for Angular 2+ :
|
This code makes the code destroy the element and reset the Stripe object when the element is unloaded.
The destroy() is needed to prevent the "IntegrationError: Can only create one Element of type card".
Resetting the Stripe object is necessary to have Stripe re-initialized on the next component mount. This is necessary in order to load remote fonts (and probably other reasons as well.)
This PR isn't throughly tested but it is working fine in my environment.