These are chat archives for ramda/ramda

25th
May 2018
lukasbash
@lukasbash
May 25 2018 14:30
Heyo people!
Quick question: I did not find any function in the library that preloads the supplied argument to a function and this fn simply returns it.
I am aware of R.identity. But is it legit to use it like const f = R.partial(R.identity, [1]) or should I go with the default arrow style version const f = () => 1? Any thoughts on this?
Mike Lambert
@lax4mike
May 25 2018 14:31
there is R.always
lukasbash
@lukasbash
May 25 2018 14:31
LOL totally my bad, thanks a lot @lax4mike :/
Mike Lambert
@lax4mike
May 25 2018 14:32
:thumbsup:
Stephan Meijer
@smeijer
May 25 2018 18:30
Is there a way to clean the memoize cache?
Mike Lambert
@lax4mike
May 25 2018 18:36
You should only memorize pure functions
Stephan Meijer
@smeijer
May 25 2018 18:39
yeah, well.. I need to debounce a promise, but based on it's arguments.
axios.get('/items/1'); 
axios.get('/items/1'); 
axios.get('/items/2');
axios.get('/items/1');
axios.get('/items/1'); // exec
axios.get('/items/2'); // exec
axios.get('/items/3');
axios.get('/items/3');
axios.get('/items/3'); // exec
so I thought, memoize the promise for a few sec :innocent:
Brad Compton (he/him)
@Bradcomp
May 25 2018 19:00
There's a difference between memoizing (stores first response) and debouncing (executes last response)
The trick with this will be debouncing per parameter
If it can be the first one that gets executed, we generally use an expiring cache. On the backend we have a simple wrapper around redis
Brad Compton (he/him)
@Bradcomp
May 25 2018 19:06
Looks like you could use something like this could work - I don't have personal experience with it though.
Stephan Meijer
@smeijer
May 25 2018 19:20

I understand. It cannot be the first response, as it's client side, and I try to cancel out requests. It's for an scrolling-list, where pages are being fetched by n items a time, while the api is triggered for each item :confounded:

So, page asks for item 1, 2, 3, 4, 5, .... While the api says, okay, here you have items 1-50, items 50-100, etc.

Based on the page offset, I can now compute the page number, (item 45 === page 0, while 95 === page 1), so we should debounce the request based on the page number. Allowing multiple pages at to be requested, but only a single requests per page.

But, not really relevant for Ramda. I was just hoping that I could fix it with R.memoizeWith.

I did find a package that can assist me though: https://www.npmjs.com/package/memoizee

thanks for thinking with me :smile:
Brad Compton (he/him)
@Bradcomp
May 25 2018 19:40
Oh cool, that makes sense