“This is the ninth day of my participation in the First Challenge 2022. For details: First Challenge 2022”

This article records a mistake I made in my work.

I’ve injected a new dependency into the constructor, as shown below:

protected checkoutService: CheckoutService

The customer encounters a compilation error when both of the following conditions are true:

(1) The customer has upgraded to the new Minor version, which I introduced with this new dependency. (2) The client extends CheckoutDeliveryService (3) the client calls the super constructor of its parent class in the constructor of its extension class.

The constructor does not pass the checkoutService input parameter I introduced in the new version, so I get syntax errors.

The correct approach is shown below:

export class CheckoutDeliveryService implements CheckoutDeliveryFacade {
  constructor(
    protected checkoutStore: Store<StateWithCheckout>,
    protected processStateStore: Store<StateWithProcess<void> >,protected activeCartService: ActiveCartService,
    protected userIdService: UserIdService,
    @Optional(a)protectedcheckoutService? : CheckoutService) {}
Copy the code

Use @optional to decorate the newly introduced constructor input parameter.

At the same time, the logic in the code needs to be changed to handle both null and non-null checkoutService cases.

  protected isCheckoutDetailsLoading$: Observable<boolean> = this
    .checkoutService
    ? this.checkoutService.isLoading()
    : this.checkoutStore.pipe(select(CheckoutSelectors.getCheckoutLoading));
Copy the code

If checkoutService is not null, then use checkoutService. IsLoading observables return; Otherwise, use the older implementation to fetch the read state of the checkout Loading from the checkoutStore for the older version.

Changes to the service code also affect the corresponding unit test code.

Now isSetDeliveryModeBusy signs, to determine the value of input conditions for another, from checkoutService. IsLoading, change into isCheckoutDetailsLoading.

So, in the unit test code, we need to create a global isCheckoutLoading$Observable:

Create a mockCheckoutService class that internally returns the global isCheckoutLoading$Observable object.

Such, at any time. We need to modify the CheckoutService isLoading return values, by calling the isCheckoutLoading $next method can flexibly control.

It is important to note that maintaining stability in large apis is a challenge. If you are changing the API library, consider the broad consequences of the change and try to anticipate any problems that may arise.

More of Jerry’s original articles can be found in “Wang Zixi “.