Hi there,

I'm learning Elm, coming from a background of creating 'Reactive' GUIs with 
RX and C#. 
The first thing I'm trying to code in elm is a 'real time text search', 
where the user types in the text input, and as he types HTTP requests are 
created. When the latest request returns with the results, they are 
populated. Pretty simple. In my RX days, I would use a pattern like this:

/*
* Typical (ish) RX expression to implement a 'throttled text search', where:
*
* 'SearchTextBoxChanges' is the stream of text changes from the text box 
input
*
* 'HttpGetSearchResults' is a function which returns a single value 
observable stream of results for the 
* given search text
*/
var searchSubscription = SearchTextBoxChanges
.Throttle(TimeSpan.FromMilliseconds(400))
.Select(x => HttpGetSearchResults(x))
.Switch()
.TimeOut(TimeSpan.FromSeconds(3))
.Subscribe(xs => PopulateResults(xs), err => 
ClearResultsAndShowErrorMessage()); 

Where the same RX subscription deals with user input de-bouncing, 
cancelling stale HTTP requests, etc. And all the state involved with that 
is contained in the subscription pipeline. But in Elm, I'm struggling to 
de-bounce anything (without reaching for a library), and finding I'm having 
to manually track the request/response correlation so I don't suffer from 
out-of-order reception of results. This is kind-of what I have (copied and 
cleaned up - won't compile):

https://gist.github.com/mandrolic/5510379bc068dfb2224e7faf2084458c

Is there a better approach here? My brain is still used to composing 
pipelines with RX, so could do with some advice to do it more the Elm way.

Andrew

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to