Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
localstripe.js: Implement unmount and destroy on Element
The Stripe.js docs do not specify much of the interaction among [`mount`], [`unmount`], and [`destroy`] so most of the following description came by experimentation. `mount` adds the Stripe element to the given DOM element. `mount` has no effect if its argument refers to the same DOM element to which the Stripe element is already mounted. It throws an exception if the Stripe element is already mounted, unless the argument refers to the same DOM element on which the Stripe element is already mounted. It also throws an exception if the Stripe element has been destroyed. `unmount` removes the Stripe element from the DOM. It is idempotent. Stripe.js throws an exception if the Stripe element has been destroyed; our version does not. `destroy` destroys the Stripe element, removing it from the DOM if necessary. There can be no more than one Stripe element at a time with a given type, so you must call `destroy` before creating another. Stripe.js throws an exception if the Stripe element has been destroyed; our version does not. This all requires some extra bookkeeping in `Element`, so it has two new "private" fields that are not present in a real Stripe object: 1. `_domChildren` tracks all of the DOM elements created by `mount`, and is used both to tell whether the Element is mounted and for `unmount` and `destroy` to remove the DOM elements. 2. `_stripeElements` keeps a reference to the `elements` object that created the `Element`, so it can make the `elements` allow another call to `create` after `destroy` is called. [`mount`]: https://stripe.com/docs/js/element/mount [`unmount`]: https://stripe.com/docs/js/element/other_methods/unmount [`destroy`]: https://stripe.com/docs/js/element/other_methods/destroy
- Loading branch information