onehungrymind/fem-enterprise-patterns

Question (Bug?) "Reducing Complexity Excerise"

Opened this issue · 0 comments

Hi Lukas,

I have an understanding question on the first exercise. I was not sure, where and how to ask ... so I went to github ;).

If I am not mistaken the total price calculated and stored in this.price is different, then the total price of all widgets stored this-widgets?

reCalculateTotal(mode: string, widgets: Widget[], widget: Widget) {
    this.widgets = this.updateWidgets(mode, widgets, widget);
    this.price = this.getTotalPrice(widgets);
  }

What I mean is, we run this.getTotalPrice(widgets), while we store on this.widgets a different collection based on the passed mode.
The total price of that collection should be different to the collection passed on this.getTotalPrice(widgets).

I have modified the function a bit to log the difference.:

 reCalculateTotal(mode: string, widgets: Widget[], widget: Widget) {
   console.log(`calling: this.getTotalPrice(this.updateWidgets(mode, widgets, widget)): ${this.getTotalPrice(this.updateWidgets(mode, widgets, widget))}`);
   console.log(`calling: this.getTotalPrice(widgets): ${this.getTotalPrice(widgets)}`);
   this.widgets = this.updateWidgets(mode, widgets, widget);
   this.price = this.getTotalPrice(widgets);
 }

Log:

PASS micro apps/micro/src/app/home/home.component.spec.ts
 HomeComponent
    should create (69 ms)
    should call updateWidgets and getTotalPrice on reCalculateTotal (35 ms)
 console.log
   calling: this.getTotalPrice(this.updateWidgets(mode, widgets, widget)): 100

     at HomeComponent.reCalculateTotal (src/app/home/home.component.ts:16:13)

 console.log
   calling: this.getTotalPrice(widgets): 0

     at HomeComponent.reCalculateTotal (src/app/home/home.component.ts:17:13)

The total price stored in this.price is 0 while the total price on all widgets stored in this.widgetsis 100.

From my understanding, the total price function getTotalPrice should be executed on the return value of updateWidgets.

I hope, I could make the issue clear.

Best
Torsten