reactjs - Javascript function syntax in React/Redux -


this may more of generic javascript(possibly es6) question, here lets see how plays out.

i encounter type of syntax daily, , beginning become annoyed not understand how stuff working under hood:

const createstorewithmiddleware = applymiddleware(reduxthunk)(createstore) 

i can see applymiddleware function, in example, taking reduxthunk argument. however, have no clue createstore doing sitting in parentheses next it.

same can go example, confused what's going on userlist:

export default connect(mapstatetoprops)(userlist) 

could explain me going on here? explanation of both appreciated, both serve different purposes, , 1 ends being expression.

this:

const createstorewithmiddleware = applymiddleware(reduxthunk)(createstore) 

is same this:

const temp = applymiddleware(reduxthunk); const createstorewithmiddleware = temp(createstore); 

(but without temp variable.)

the code calling applymiddleware argument reduxthunk; applymiddleware returns function. then, code calling function createstore argument.

here's simple example no libs or similar:

function createadder(valuetoadd) {      return function(valuetoaddto) {          return valuetoaddto + valuetoadd;      };  }    // doing @ once  const result1 = createadder(5)(10);  console.log(result1); // 15    // doing step step  const addfiveto = createadder(5);  const result2 = addfiveto(10);  console.log(result2); // 15


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -