♻️ 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.ApplePayConfig = null;
this.buttons = []; this.buttons = [];
buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => { this.onContextBootstrap = this.onContextBootstrap.bind( this );
this.contextHandler = ContextHandlerFactory.create( buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
bootstrap.context, }
buttonConfig,
ppcpConfig,
bootstrap.handler
);
const button = ApplePayButton.createButton( async onContextBootstrap( bootstrap ) {
bootstrap.context, this.contextHandler = ContextHandlerFactory.create(
bootstrap.handler, bootstrap.context,
buttonConfig, this.buttonConfig,
ppcpConfig, this.ppcpConfig,
this.contextHandler 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. this.buttons.push( button );
await this.init();
button.configure( this.ApplePayConfig ); // Ensure ApplePayConfig is loaded before proceeding.
button.init(); await this.init();
} );
button.configure( this.ApplePayConfig );
button.init();
} }
async init() { async init() {

View file

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