Every time when a message triggers. The update function applies twice but because of distinctUntilRefChanged operator the second model doesn't emit to the downstream.
Minimal, Reproducible Example
The example in the repository is prone to this issue.
Steps to Reproduce
Just add a trace to the update function to reveal the function call.
update :: Message -> Model -> Model
update = case _ of
Increase -> trace "increase" (\_ -> (_ + 1))
Decrease -> (_ - 1)
Expected Behavior
On each message the update function should just be called once.
Actual Behavior
2x call of update function on each message.
Browsers Affected
[x] Chrome
[x] Firefox
[x] Edge
[x] Safari 11
[x] Safari 10
[x] IE 11
Versions
Monarch: v0.0.0
Etiology
The issue is because the eModel is an Event not a Queue (BTW we should choose a better name for it :|). Each time when we subscribe to the eModel event it adds a subscriber to qMessage queue and each subscriber will be called separately.
Description
Every time when a
message
triggers. The update function applies twice but because ofdistinctUntilRefChanged
operator the secondmodel
doesn't emit to the downstream.Minimal, Reproducible Example
The example in the repository is prone to this issue.
Steps to Reproduce
Just add a
trace
to theupdate
function to reveal the function call.Expected Behavior
On each
message
theupdate
function should just be called once.Actual Behavior
2x call of
update
function on eachmessage
.Browsers Affected
Versions
Etiology
The issue is because the
eModel
is anEvent
not aQueue
(BTW we should choose a better name for it :|). Each time when we subscribe to theeModel
event it adds a subscriber toqMessage
queue and each subscriber will be called separately.https://github.com/the-dr-lazy/purescript-monarch/blob/403bcfa4030ff4a9f707ca15c824b196c2f298d1/src/Monarch/Platform.purs#L126-L127
Solution
The
eModel
event should be convert to a queue.