Kamran Ayub
๐จโ๐ฉโ๐ฆ ๐ถ๐ถ
๐ฒ๐ฎ๐จโ๐ป๐๐ธ
Work at Target
To make my apps easier to maintain
To make my apps easier to scale
Easy to extend
ย
Easy to collaborate on
ย
Easy to reuse code
Easy to refactor
ย
Easy to understand
ย
Easy to test
Folder Layout
State & Reducers
Actions
Props & State
Action Creators
+ bonus: Jest / CSS-in-JS
Folder Layout
Folder Layout
Not scalable as screens nest further
Folder Layout
Maintains F12 Go to Definition behavior
Folder Layout
Folder Layout
Folder Layout
There's an open issue for emulating "module directories" functionality from Webpack/Jest to allow paths like:
Folder Layout
ย
State & Reducers
No need to define an entire representative "State" interface. Just export what it will end up being (typeof)
Folder Layout
Each screen will define its state shape
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
State & Reducers
Folder Layout
A bit wordy, but pays off at scale
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Actions
Folder Layout
State & Reducers
Action Creators
Folder Layout
Actions
State & Reducers
mapDispatchToProps makes it easier to test component in isolation
Action Creators
Folder Layout
Actions
State & Reducers
Action Creators
Folder Layout
Actions
State & Reducers
Action Creators
ย
Folder Layout
Actions
State & Reducers
Props & State
Folder Layout
Actions
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Can pull into type alias and share
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Need a way to get "dispatch" and separate Redux state props vs. "own" props
Extract stateless type alias to encapsulate our State and reduce DispatchProp usage
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Same as stateless, create encapsulated Redux component type
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Split Redux connected component from "raw" component for easier isolated testing
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
Props & State
Action Creators
State & Reducers
Folder Layout
Actions
BONUS
Action Creators
State & Reducers
Using emotion CSS-in-JS
Doesn't really have any "weirdness" with TypeScript
ย
For Jest testing and Enzyme, reference the code for deeper examples of async testing / Redux testing