nkfoss / ohm-str

0 stars 0 forks source link

SLC method handleRouteParams calls fetchWorkout #45

Closed nkfoss closed 4 years ago

nkfoss commented 4 years ago

This is because the subscription is setup incorrectly. This should be as a subscription property in the component, and then handled in OnDestroy.

nkfoss commented 4 years ago

It seems like my initial thought on handling this issue was wrong. Here's what I tried:

// SetList Component properties
paramsSub: Subscription;
//setupSubs() 
this.paramsSub = this.activatedRoute.params
        .pipe(takeUntil(this.unsubNotifier))
        .subscribe(
            (params: Params) => {
                this.date = params['date'];
                this.workoutService.fetchWorkout(this.date);
            }
        );

Once again, fetchWorkout() is getting called in this process. We may just have to accept this and find an appropriate place to use it.

(I suspect this has something to do with the params subscription being something the Angular handles by default. The other subscriptions in setupSubs() are subscribing to an observables that are returned from my custom functions. However, the params sub has two key differences:

  1. Params is a property of the activated route, not something returned by a function (like the other subscriptions).
  2. Usually when you subscribe to params, you don't need to explicitally unsubscribe, because Angular does this behind the scenes (though you can do it if you want to). I'll bet that Angular also does other things behind the scenes that triggers the Subscription to fire immediately. This is not the case with the other subscriptions - they don't fire when the subscription is defined, only when they receive an update.
nkfoss commented 4 years ago

Fixed for now. See reference above.