These are chat archives for ramda/ramda

22nd
Oct 2016
Markus Pfundstein
@MarkusPfundstein
Oct 22 2016 06:46
Could you make a lens on a mongoose object which saves on set
?
Jason Lengstorf
@jlengstorf
Oct 22 2016 23:36
Hey, everyone! I'm working on an article/video walkthrough of building a small, functional app. However, I'm not an expert in FP, so I'd be really grateful for a code review and/or constructive criticism. I'm especially concerned about the way I'm creating/appending DOM elements, which feels distinctly non-functional; I've had a hard time finding examples of FP that actually manipulate the DOM, though. Here's the code: https://github.com/jlengstorf/instagram-feed/blob/feature/functional-programming/src/scripts/instagram-feed-reader.js#L185-L253
Thanks in advance!
David Boyer
@mangr3n
Oct 22 2016 23:52
so think point free functions. Meaning, pure functions waiting for the data at the end. What would the function signature look like for that createImage function if all of it's side effecting components were the last argument of a curried function?
Jason Lengstorf
@jlengstorf
Oct 22 2016 23:55
That's where I got tripped up — I built functions to create an <img>, but I ended up needing to juggle a lot of arguments, and trying to chain it all together melted my brain. Have you seen any examples of doing this that I can look at?
David Boyer
@mangr3n
Oct 22 2016 23:56
@jlengstorf , the last argument to the curried function is a node creator (document), leave it out. Also, the attachpoint is the other data point. So, my function signature might look like this:
const createImage = R.curry( (image, attachPointSelector, nodeSource) => {
    ...
});
So, until you add the document as the final argument it's a pure function... When you attach that, it brings side effecting inside.
Jason Lengstorf
@jlengstorf
Oct 22 2016 23:58
@mangr3n Okay — I'm with you so far. The part that I'm having trouble with, though, is that I'm creating 4 DOM elements and appending them in various orders.
David Boyer
@mangr3n
Oct 22 2016 23:59
If you actually make nodeSource implement only the methods you need, you can in fact build an adapter for document but mock it to output a string in an implementation for testing. or a vdom tree using one of the virtual-dom implementations.
Jason Lengstorf
@jlengstorf
Oct 22 2016 23:59
Do you have any examples that, say, create a paragraph, insert that into a div, and then append that to the DOM somewhere? The intermediate steps are what I'm struggling with.