♻️ Further streamline button-manager classes

This commit is contained in:
Philipp Stracker 2024-10-07 12:34:05 +02:00
parent 060dedaae9
commit 0a212edb89
No known key found for this signature in database
2 changed files with 46 additions and 41 deletions

View file

@ -11,30 +11,33 @@ class ApplePayManager {
this.ApplePayConfig = null;
this.buttons = [];
buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
ppcpConfig,
bootstrap.handler
);
this.onContextBootstrap = this.onContextBootstrap.bind( this );
buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
}
const button = ApplePayButton.createButton(
bootstrap.context,
bootstrap.handler,
buttonConfig,
ppcpConfig,
this.contextHandler
);
async onContextBootstrap( bootstrap ) {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
this.buttonConfig,
this.ppcpConfig,
bootstrap.handler
);
this.buttons.push( button );
const button = ApplePayButton.createButton(
bootstrap.context,
bootstrap.handler,
this.buttonConfig,
this.ppcpConfig,
this.contextHandler
);
// Ensure ApplePayConfig is loaded before proceeding.
await this.init();
this.buttons.push( button );
button.configure( this.ApplePayConfig );
button.init();
} );
// Ensure ApplePayConfig is loaded before proceeding.
await this.init();
button.configure( this.ApplePayConfig );
button.init();
}
async init() {

View file

@ -11,33 +11,35 @@ class GooglepayManager {
this.googlePayConfig = null;
this.transactionInfo = null;
this.contextHandler = null;
this.buttons = [];
buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
ppcpConfig,
bootstrap.handler
);
this.onContextBootstrap = this.onContextBootstrap.bind( this );
buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
}
const button = GooglepayButton.createButton(
bootstrap.context,
bootstrap.handler,
buttonConfig,
ppcpConfig,
this.contextHandler
);
async onContextBootstrap( bootstrap ) {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
this.buttonConfig,
this.ppcpConfig,
bootstrap.handler
);
this.buttons.push( button );
const button = GooglepayButton.createButton(
bootstrap.context,
bootstrap.handler,
this.buttonConfig,
this.ppcpConfig,
this.contextHandler
);
// Ensure googlePayConfig and transactionInfo are loaded.
await this.init();
this.buttons.push( button );
button.configure( this.googlePayConfig, this.transactionInfo );
button.init();
} );
// Ensure googlePayConfig and transactionInfo are loaded.
await this.init();
button.configure( this.googlePayConfig, this.transactionInfo );
button.init();
}
async init() {