♻️ Make internal attributes private

This commit is contained in:
Philipp Stracker 2024-10-08 14:26:46 +02:00
parent 0d72641ded
commit 35473df661
No known key found for this signature in database
2 changed files with 41 additions and 30 deletions

View file

@ -3,50 +3,55 @@ import ApplePayButton from './ApplepayButton';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
class ApplePayManager {
#namespace = '';
#buttonConfig = null;
#ppcpConfig = null;
#applePayConfig = null;
#contextHandler = null;
#buttons = [];
constructor( namespace, buttonConfig, ppcpConfig ) {
this.namespace = namespace;
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.ApplePayConfig = null;
this.buttons = [];
this.#namespace = namespace;
this.#buttonConfig = buttonConfig;
this.#ppcpConfig = ppcpConfig;
this.onContextBootstrap = this.onContextBootstrap.bind( this );
buttonModuleWatcher.watchContextBootstrap( this.onContextBootstrap );
}
async onContextBootstrap( bootstrap ) {
this.contextHandler = ContextHandlerFactory.create(
this.#contextHandler = ContextHandlerFactory.create(
bootstrap.context,
this.buttonConfig,
this.ppcpConfig,
this.#buttonConfig,
this.#ppcpConfig,
bootstrap.handler
);
const button = ApplePayButton.createButton(
bootstrap.context,
bootstrap.handler,
this.buttonConfig,
this.ppcpConfig,
this.contextHandler
this.#buttonConfig,
this.#ppcpConfig,
this.#contextHandler
);
this.buttons.push( button );
this.#buttons.push( button );
// Ensure ApplePayConfig is loaded before proceeding.
await this.init();
button.configure( this.applePayConfig );
button.configure( this.#applePayConfig );
button.init();
}
async init() {
try {
if ( ! this.applePayConfig ) {
this.applePayConfig = await window[ this.namespace ]
if ( ! this.#applePayConfig ) {
this.#applePayConfig = await window[ this.#namespace ]
.Applepay()
.config();
if ( ! this.applePayConfig ) {
if ( ! this.#applePayConfig ) {
console.error( 'No ApplePayConfig received during init' );
}
}
@ -56,7 +61,7 @@ class ApplePayManager {
}
reinit() {
for ( const button of this.buttons ) {
for ( const button of this.#buttons ) {
button.reinit();
}
}

View file

@ -2,10 +2,16 @@ import ApplePayButton from './ApplepayButton';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
class ApplePayManagerBlockEditor {
#namespace = '';
#buttonConfig = null;
#ppcpConfig = null;
#applePayConfig = null;
#contextHandler = null;
constructor( namespace, buttonConfig, ppcpConfig ) {
this.namespace = namespace;
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.#namespace = namespace;
this.#buttonConfig = buttonConfig;
this.#ppcpConfig = ppcpConfig;
/*
* On the front-end, the init method is called when a new button context was detected
@ -17,26 +23,26 @@ class ApplePayManagerBlockEditor {
async init() {
try {
this.applePayConfig = await window[ this.namespace ]
this.#applePayConfig = await window[ this.#namespace ]
.Applepay()
.config();
this.contextHandler = ContextHandlerFactory.create(
this.ppcpConfig.context,
this.buttonConfig,
this.ppcpConfig,
this.#contextHandler = ContextHandlerFactory.create(
this.#ppcpConfig.context,
this.#buttonConfig,
this.#ppcpConfig,
null
);
const button = ApplePayButton.createButton(
this.ppcpConfig.context,
this.#ppcpConfig.context,
null,
this.buttonConfig,
this.ppcpConfig,
this.contextHandler
this.#buttonConfig,
this.#ppcpConfig,
this.#contextHandler
);
button.configure( this.applePayConfig );
button.configure( this.#applePayConfig );
button.init();
} catch ( error ) {
console.error( 'Failed to initialize Apple Pay:', error );