I am using Ramda.js for selector functions, to access data in a Redux store. What I want is to define my selectors as functions not referencing the state
that the selectors act on, like:
const getUserName = path(['user', 'name']);
const name = getUserName({
user: {
name: 'Some Name'
}
});
This is easy for simple selectors, but sometimes becomes a problem for composed selectors.
Here is an example, where some items
needs to be resolved, referenced by their id
on an object:
const getItemById = id => state => path(['items', id], state);
const getConnectedItemIds = obj => path(['items'], obj);
const getItemsFromObj = obj => state => {
const ids = getConnectedItemIds(obj);
return ids.map(id => getItemById(id)(state));
};
The first function can easily be expressed without reference to state
, and the second function without obj
, something I believe is called point-free style. But how to write the third function without state
?
I am looking for how to rewrite the third function using Ramda, but also rules and procedures regarding this, such as (without knowing if its true):
All composed functions need to have state
as their last argument to be able to pull it out in the final composition.