js chicago meetup 2/23/16 - redux & routes

35
redux & routes https://github.com/ndreckshage/js-chicago-redux-and-routes

Upload: nick-dreckshage

Post on 10-Feb-2017

347 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: JS Chicago Meetup 2/23/16 - Redux & Routes

redux & routeshttps://github.com/ndreckshage/js-chicago-redux-and-routes

Page 2: JS Chicago Meetup 2/23/16 - Redux & Routes

nick dreckshage sr. ui engineer @ raise.com https://github.com/ndreckshage @nickdreckshage

Page 3: JS Chicago Meetup 2/23/16 - Redux & Routes

redux & routes…a bit broader…

easing js fatigue

Page 4: JS Chicago Meetup 2/23/16 - Redux & Routes

babel

webpack

react

react-router

eslint

npm

node

redux-simple-router

redux-routerredux

redux-devtools

redux-thunk

immutable.js

universal/isomorphic

es6

1000’s of react-starter-kits

css modules

hot loading

time traveling

ember/angular/etc

Page 5: JS Chicago Meetup 2/23/16 - Redux & Routes

a lot of people have made many really great things

a lot people want to build very ambitious things

Page 6: JS Chicago Meetup 2/23/16 - Redux & Routes

but it can be overwhelming!

Page 7: JS Chicago Meetup 2/23/16 - Redux & Routes

https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4#.v956cs93z

Page 8: JS Chicago Meetup 2/23/16 - Redux & Routes

https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4#.v956cs93z

Page 9: JS Chicago Meetup 2/23/16 - Redux & Routes

js fatigue applies to both setup & building a spa with react & redux.

ember / ember-cli does some really nice things. best practices for a redux spa?

convention -> configuration -> happy medium

Page 10: JS Chicago Meetup 2/23/16 - Redux & Routes

https://github.com/raisemarketplace/ground-control

https://github.com/ndreckshage/sambell

Structured, universal, SPA architecture

CLI to create universal, SPA with a single file

Page 11: JS Chicago Meetup 2/23/16 - Redux & Routes

easing js fatigue…2 new things…

Page 12: JS Chicago Meetup 2/23/16 - Redux & Routes

GroundControl goals (ease building): simplify react/redux/spa architecture. scalable & organized. treat routes as isolated, stateless pages - like a server side refresh. provide opinionated reducer structure so developer doesn’t have to think about it. universal data fetching api to easily control rendering.

Page 13: JS Chicago Meetup 2/23/16 - Redux & Routes

sambell goals (ease getting started): ultimate simplicity. a universal, single page app with a single file. index.php ease. not a starter kit, move complexity behind the scenes. app code only. nice defaults but highly configurable. incremental complexity.

Page 14: JS Chicago Meetup 2/23/16 - Redux & Routes

redux & routes…why it’s hard

Page 15: JS Chicago Meetup 2/23/16 - Redux & Routes

disconnected global application state

global route state

https://github.com/ndreckshage/js-chicago-redux-and-routes/tree/master/1-react-router-and-redux

Page 16: JS Chicago Meetup 2/23/16 - Redux & Routes

react-router-redux (previously redux-simple-router) connects them.

Page 17: JS Chicago Meetup 2/23/16 - Redux & Routes

unpredictable imo, routes makes my immutable,

testable reducers / application state feel like a global, mutable variable.

https://github.com/ndreckshage/js-chicago-redux-and-routes/tree/master/2-react-router-and-redux

Page 18: JS Chicago Meetup 2/23/16 - Redux & Routes

• what did the previous route do to my application state?

• if i navigate back to a previous route, is the previous state still there? do i need to manually reset state? garbage collection?

• how do i add new reducers to the store for a route that needs it. if a new route is added, i need to change everything? code splitting?

Page 19: JS Chicago Meetup 2/23/16 - Redux & Routes

flat structure great at first…

Page 20: JS Chicago Meetup 2/23/16 - Redux & Routes

still ok…

Page 21: JS Chicago Meetup 2/23/16 - Redux & Routes

0 confidence what my state looks like!

Page 22: JS Chicago Meetup 2/23/16 - Redux & Routes

route based state organizationBy fundamentally organizing state based on the routing structure, we simplify our ‘world view’ to our active route.

GroundControl: • Organizes Redux reducers based on routes • Automatic nested reducers • Coordinates top level application state (still global) • Keeps reducer implementations intact (testable) • Clears out stale state, leaves parent route state. • Feels more like server side dev (ctrl+f5)

https://github.com/ndreckshage/js-chicago-redux-and-routes/tree/master/3-react-router-and-redux

Page 23: JS Chicago Meetup 2/23/16 - Redux & Routes
Page 24: JS Chicago Meetup 2/23/16 - Redux & Routes
Page 25: JS Chicago Meetup 2/23/16 - Redux & Routes
Page 26: JS Chicago Meetup 2/23/16 - Redux & Routes

data fetching• react router leaves data fetching up to you. • server side, sync makes more sense. client side async might. so you

decide! inverted data fetching api. and it’s universal. • makes sense for a router. colocated component data fetching

makes sense for falcon / graphql (build queries).

Page 27: JS Chicago Meetup 2/23/16 - Redux & Routes

too many tools…so much setup… 1774 (and counting) starter kits…

https://github.com/search?utf8=%E2%9C%93&q=react+starter&type=Repositories&ref=searchresults

Page 28: JS Chicago Meetup 2/23/16 - Redux & Routes

https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4#.v956cs93z

Page 29: JS Chicago Meetup 2/23/16 - Redux & Routes

http://blog.vjeux.com/2015/javascript/challenge-best-javascript-setup-for-quick-prototyping.html

Page 30: JS Chicago Meetup 2/23/16 - Redux & Routes

why not a starter kit? dislike being thrown in middle of someone else’s code,

especially when getting started. out of site out of mind. app code only.

Page 31: JS Chicago Meetup 2/23/16 - Redux & Routes

1 file. no webpack, .eslintrc, .babelrc, node_modules, client setup, server setup,

store setup, etc.

Page 32: JS Chicago Meetup 2/23/16 - Redux & Routes

configurable!

https://github.com/ndreckshage/sambell/blob/master/src/app/gerty.defaults.js

Page 33: JS Chicago Meetup 2/23/16 - Redux & Routes

for prototypes. but could be for prod, why not.

Page 34: JS Chicago Meetup 2/23/16 - Redux & Routes

last thoughts: react ecosystem is really remarkable. but there is

room to make application development easier for us plebs.

Page 35: JS Chicago Meetup 2/23/16 - Redux & Routes

thanks! questions?