Skip to content

Commit

Permalink
Instantiates reporter only on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Jan 5, 2024
1 parent 774e5c5 commit 6680731
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 1 deletion.
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

0 comments on commit 6680731

Please sign in to comment.