wonism / gatsby-advanced-blog

Gatsby starter for advanced blog
https://wonism.github.io/
MIT License
125 stars 34 forks source link

Question: What is const getAppSubState = get('app'); storing exactly in store/app/selectors.js line 4 #10

Closed rjpruitt16 closed 6 years ago

rjpruitt16 commented 6 years ago

I am trying to manipulate code to create a interest page for myself. I am not sure lodash/fp "get" is doing here. When I look at the docs https://lodash.com/docs/4.17.10#get, it specifically states the get function takes two arguments. You the get function in store/app/selectors.js and components/resume/index.jsx like this. What are you storing in these variables using the get function, and how are you only using one argument.

wonism commented 6 years ago

Below codes will same as comment.

import fp from 'lodash/fp';
// import _ from 'lodash';

const resume = fp.get('markdownRemark')(data);
// const resume = _.get(data, 'markdownRemark');
// it can also be, const resume = fp.get('markdownRemark', data);

And I recommend two pages to read.


and about lodash. _ and fp are different. fp is wrapped and it can help user to curry easily. You can refer this page. https://github.com/lodash/lodash/wiki/FP-Guide

FYI. it explains what is currying

/* not curried function */
function sumOfThreeThings(x, y, z) {
  return x + y + z;
}

sumOfThreeThings(1, 2, 3); // 6

/* curried function */
const sumOfThreeThings = x =>
  y =>
    z =>
      x + y + z;
sumOfThreeThings(1)(2)(3); // 6