Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upOrder of port declarations influences behaviour #896
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Aug 10, 2017
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Aug 10, 2017
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
zwilias
Aug 10, 2017
Member
Note that - and this is the truly unexpected part - flipping the order in which the ports are declared fixes this issue, since this directly corresponds to the order in the managers object.
https://ellie-app.com/3YKLTxbsg7na1/2 (only difference with /1 is flipping the order of ports)
Subs first means subscriptions will be processed first
port toElm : (String -> msg) -> Sub msg
port toJS : String -> Cmd msgSubs last means subs will be processed last.
port toJS : String -> Cmd msg
port toElm : (String -> msg) -> Sub msgThe order in which ports are declared really should not impact behaviour.
|
Note that - and this is the truly unexpected part - flipping the order in which the ports are declared fixes this issue, since this directly corresponds to the order in the https://ellie-app.com/3YKLTxbsg7na1/2 (only difference with Subs first means subscriptions will be processed firstport toElm : (String -> msg) -> Sub msg
port toJS : String -> Cmd msgSubs last means subs will be processed last.port toJS : String -> Cmd msg
port toElm : (String -> msg) -> Sub msgThe order in which ports are declared really should not impact behaviour. |
zwilias commentedAug 10, 2017
SSCCE
https://ellie-app.com/3YKLTxbsg7na1/1
TL;DR
sendupdatewhich modifies the model to enable a subscription and triggers that outgoing portsendis called before the subscription handler is scheduled, hence dropping the message.Problem statement
Setting state to enable a subcription and triggering an outgoing port which synchronously calls back into Elm at the same time leads to this response being missed. This can easily come up when using a subscription-structure like advocated by elm-spa-example.
This is surprising since the user has already configured their model so that a subscription should be enabled, and how/when those subscriptions actually go into effect is an implementation detail the user shouldn't need to worry about.
Possible fix
Ensuring that subscription handlers are scheduled before commands are scheduled seems like a fix; I'm not sure if there are potential adverse effects to doing so.