Open 8483 opened 5 years ago
@8483 could you please share a bit more detail about your HTTP request? Are you sending/requesting data from a server/service? Elm typically does this with a Task. in JS land we would need to create an event listener.
@nelsonic That was a quick response. :)
Yes, I am talking about getting data from a RESTful API and updating the model with the response data.
Task
and Command
were always confusing for me compared to Message
. I still don't fully understand why they are required and what the difference is.
As far as I got it, commands are used as a message sent after a message, and tasks as handling impure things.
It would be cool if they were explained via a Javascript example, but sadly, I am unable to contribute the explanation as I don't fully grasp them.
@8483 your understanding of Task
, Command
and Message
are good. ✅
I tend to agree that in some cases explaining Elm Architecture concepts in JS is useful for people who have good JS knowledge/experience. But I think Evan is pitching his guide/language at people who aren't JS experienced ... 🤔
For what it is worth, I would definitely be interested in seeing the elmish Todo app expanded to elmishly talk to APIs/servers with vanilla JS. What would elm commands look like in the vanilla JS elmish Todo app? Would we also have to add on to elmish.js or perhaps make our own Http.js and JSON.js (for encoding form inputs) modules? I don't know if there's still any interest in this, but I would love to see something like that here. Following the tutorial so far has been very useful for me. If anyone knows of a similar elmish tutorial that also covers API/server communication, that would also interest me.
The ELM Architecture handles HTTP requests outside of the
mount
function, as it considers them impure.Do we simply execute the request inside of the
update
switch statement i.e. break the pattern?