Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes dynamic removal of subscriptions and adjustments from CheckoutPricing/Attachment #403

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/recurly/pricing/checkout/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export default class Attachment extends Emitter {
const subscriptionGroups = groupBy(elems.all, el => dom.data(el, 'recurlySubscription'));
delete subscriptionGroups.undefined;

// Removes all subscriptions and adjustments, as there is not a clean
// way to detect individual item removal without using observers
this.pricing.clearSubscriptions();
this.pricing.clearAdjustments();

// Builds a SubscriptionPricing instance per subscription element group
// This probably needs to be collected by a Promise.all
Promise.all(Object.keys(subscriptionGroups).map(id => {
const subscriptionElems = groupBy(subscriptionGroups[id], el => dom.data(el, 'recurly'));

Expand Down
14 changes: 14 additions & 0 deletions lib/recurly/pricing/checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ export default class CheckoutPricing extends Pricing {
}, this);
}

/**
* Clears all subscriptions
*/
clearSubscriptions () {
this.items.subscriptions = [];
}

/**
* Clears all adjustments
*/
clearAdjustments () {
this.items.adjustments = [];
}

/**
* Checks whether the current subscriptions will allow the given currency code
*
Expand Down