-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZipCodes could use Future instead of promises #13
Comments
I agree! I have started to play around with ramda-fantasy futures too. (I was the one who converted over the zipcodes example to snabbdom + flyd here). I was thinking of just wrapping XHR as described here, instead of an external library (superagent-future), but otherwise similar to your code. The other hesitation I had was that Elm's Tasks seem more specialized than Futures to me and I wanted to understand them better. But if you want to open a PR, I'm sure @paldepind will give excellent feedback! |
@ericgj @paldepind the problem with just wrapping XHR is that when we need to POST things or PUT things we'll have to write wrappers for those as well. Which will effectively end up being a new xhr library. super-agent future is actually my hack of superagent... I just tap into its
Then there are spawn and sleep that are quite esoteric for me (although it seems like spawn is something like fork...maybe) and a bunch of various arity maps that can be done manually. As Result is basically just a data type data Result = Err String | Ok a We can just return it from our At least that's how I see it. |
Thanks for putting together this table, very useful. They are similar... if you squint ,) One difference is Elm Tasks don't have Another thing that confused me was the 'free' error type in the Task, how that would translate to JS, but I think that's so you can get from/to the Result Err type in Re. Anyway, it's up to @paldepind of course, but maybe you'd want to drop your code in as a separate example here -- |
@ericgj I'm going to research into Elm threads and get back to you on |
Looking forward to seeing an implementation with 👍 on separate example. |
Hello all! I've just pushed a zip codes example that uses futures. I've also made a few other improvements to the example. For instance while a result is being loaded it is indicated with a text. I'd love to hear your opinions on the example! |
Nice! I learned a lot reading through this. I like the way your top-level Nice also to see ramda lenses in action. |
Great. I'm happy to hear that.
Thank you. I like it as well. Using an array makes it very easy to trigger multiple or zero actions. For instance if a component is initialized both the parent and a subcomponent might want to make requests.
Yes. You're right. It does in fact. Calling the update function is handled in the top and one can only trigger async operations based on the current given state (which I think is sensible). |
Yes i was thinking of something similar to adapt from the Elm async solution. And it seems that the The issue with deeply nested components can also be solved here: the future action bubbles up through parent components so they are able to wrap the 'Future Action' in another Future Action like they wrap 'normal actions' triggered from the view of child compnents (elm example of Pair of random GIF viewers). |
Yeah. I wish I understood this better, it seems crucial. In Elm, map : (a -> b) -> Effects a -> Effects b
map func effect =
case effect of
Batch effectList ->
Batch (List.map (map func) effectList)
-- skipping Task, None and Tick effect types Is that effectively the same as // in a parent component update function
const [childState, childFutures] = childComponent.update(someAction, childState);
return [ R.set(childLens, childState), R.map( (future) => future.map(parentAction), childFutures ) ]; ? So essentially when the future resolves from the top, the result will be chained through actions from the originating component at the bottom, bubbling up to the top? I have to see it to believe it...! |
FYI, I tried out this future chaining to handle nested updates from HTTP requests (PR #16) -- it works great! |
I'm experimenting with elm-to-js as well (I guess you already know from twitter). I'm yet to switch to your union-types though:)
One thing that could be nice, taken that you/we are going down a functional rabbit hole, is to use fantasy land data types. Future could be nice for the ZipCodes example in particular (and really close to what is happening in the elm code). Using Future we can do it like here
The text was updated successfully, but these errors were encountered: