简体   繁体   中英

How to capture Server Events in Elm

I am trying to capture Server Events in Elm. But I couldn't found a library. Or I don't know default http library can do this.

Here is JavaScript code I wanted to write in Elm.

var source = new EventSource(
    '/event-stream?channel=channel&t=' + new Date().getTime());

There is obvious work around is I write JS code and port in Elm application. But I guess that will pollute the code. If I can have both in Elm, and possible I can join in Stream/Signal application would become fully reactive to Server. That is the end goal.

Please let me know if any further details are required.

PS: Above code is basic Html5 code.

As of Elm 0.16, pushing values from the event stream in through a port is the best option for this. There's no way to access and instantiate an EventSource within Elm code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM