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

Instantiates events only on demand #865

Merged
merged 1 commit into from
Jan 5, 2024
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
Instantiates reporter only on demand
  • Loading branch information
chrissrogers committed Jan 5, 2024
commit 66807318be963dd91614d36c485db2e11965f367
10 changes: 10 additions & 0 deletions lib/recurly.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const DEFAULTS = {
litle: { sessionId: undefined },
braintree: { deviceData: undefined }
},
report: false,
risk: {
threeDSecure: { preflightDeviceDataCollector: true }
},
Expand Down Expand Up @@ -142,11 +143,14 @@ export class Recurly extends Emitter {
this.readyState = 0;
this.request = new Request({ recurly: this });
this.config = deepAssign({}, DEFAULTS);

if (options) this.configure(options);

this.bankAccount = {
token: bankAccount.token.bind(this),
bankInfo: bankAccount.bankInfo.bind(this)
};

this.reporter = new Reporter({ recurly: this });

this.Pricing = () => new SubscriptionPricing(this); // deprecated
Expand Down Expand Up @@ -222,6 +226,8 @@ export class Recurly extends Emitter {
* @param {Boolean} [options.cors] Enables data transmission over XHR+CORS
* @param {Array} [options.required] Adds additional field requirements for
* tokenization. ex: ['cvv']
* @param {Boolean} [options.report] Enables remote event reports
*
* @public
*/
configure (options) {
Expand Down Expand Up @@ -262,6 +268,10 @@ export class Recurly extends Emitter {
deepAssign(this.config.risk, options.risk);
}

if ('report' in options) {
this.config.report = options.report;
}

if ('parent' in options) {
this.config.parent = options.parent;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Reporter {
* @private
*/
get shouldDispatch () {
return this.recurly.isParent;
return this.recurly.isParent && this.recurly.config.report;
}

/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/unit/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export function initRecurly (recurly, opts) {
// prevents itinerant event logging workers from dispatching
sinon.stub(recurly.reporter, 'send');
}

recurly.configure(merge({
publicKey: 'test',
api: `${window.location.protocol}//${window.location.host}/api`
}, opts));

return recurly;
}

Expand Down
Loading