Bubuhubu87 / bc-jokes

MIT License
0 stars 0 forks source link

Message service does not work properly #7

Closed adrianpawlik closed 3 years ago

adrianpawlik commented 3 years ago

After switching in between categories and displaying a few jokes in a row, on a new screen all messages are being displayed.

Bubuhubu87 commented 3 years ago

I will check it, thanks.

Bubuhubu87 commented 3 years ago

changing observer initialization to constructor with first() operator this.observableSwitchMap = this.dataSharedService.currentMessage.pipe( first(), switchMap((category: Category) => this.JokesService.getRandomJokeBy(category)));

and unsubscribe in getRandomJoke

this.subscription$ = this.observableSwitchMap.subscribe((result: Joke) => { this.fetchJoke(result); this.subscription$.unsubscribe(); },

do the job.

Problem is in creation subscriber every time when we hit the button. To fix.

Bubuhubu87 commented 3 years ago

Fixed