The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Redux: Writing a Counter Reducer with Tests

Redux: Writing a Counter Reducer with Tests

2:36
You will learn how to write the reducer for the counter application in a test driven development way, as well as the conventions in implementing reducers.
Watch this lesson now
Avatar
egghead.io

You will learn how to write the reducer for the counter application in a test driven development way, as well as the conventions in implementing reducers.

Avatar
Nathaniel

Would you mind explaining more as to why you define counter as a const and an arrow function? What is meant by it has clearer semantics? Thanks so much, really enjoying the series so far!

Avatar
Dan Abramov

Nathaniel,

For historical reasons JS function declarations have weird semantics. "function" is not block-scoped (that it, behaves like "var" rather than like ES6 "let" or "const"), it is hoisted (a very weird thing to cloud beginners' heads with), it has "this" context which is frustrating to explain when you're just teaching some library's API, etc.

See also:

https://medium.com/@ryanflorence/functions-without-function-bc356ed34a2f

https://twitter.com/sebmarkbage/status/638531311477522433

In reply to Nathaniel
Avatar
rphansen91

Which library are you using for expect?

Avatar
rphansen91

Figured out through later episodes it is loaded through as a script tag on the HTML src="https://wzrd.in/standalone/expect@latest". Loving the series so far, same architecture as ELM but with JS!

In reply to rphansen91
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?