gcanti / elm-ts

A porting to TypeScript featuring fp-ts, rxjs6 and React
https://gcanti.github.io/elm-ts/
MIT License
300 stars 13 forks source link

Bug Fix: call subscriptions with initial model, fixes #10 #11

Closed minedeljkovic closed 6 years ago

minedeljkovic commented 6 years ago

This seems like a hacky way to fix #10.

The issue seems to be somewhere in calling share() on model$ stream, and subscribing to it with two streams html$ and sub$ where the second one is built with switchMap. Without change from this PR, subscriptions function passed to model$.switchMap does not get called with initial model.

Few more observations:

  1. If share() method call is removed on model$ stream, subscriptions function is called with initial model. That leads to undesired behavior where calling modelCompare and mapping of state to model happens twice, which was surely the reason to introduce share().
  2. If html$ subscription is removed and sub$ remains the only subscription to model$, subscriptions function is called with initial model.

With my limited knowledge of rxjs this was the only fix I could find, which has no undesired behavior changes.

gcanti commented 6 years ago

@minedeljkovic looks good to me

gcanti commented 6 years ago

Thanks