More Related Content
Similar to Redux JavaScript Meetup - Talentica, Saturday, July 6, 2019 (20)
Redux JavaScript Meetup - Talentica, Saturday, July 6, 2019
- 1. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Beginner to advanced
- 2. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ ]
Component-2
Component-1
Component-3
Display
Component
Parent Component
Child Components
- 3. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ ]
Component-2
Component-1
Component-3
Display
Component
{id: 1}
Parent Component State
Child Components
- 4. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ {id: 1} ]
Component-2
Component-1
Component-3
Display
Component
Parent Component State
- 5. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ {id: 1} ]
Component-2
Component-1
Component-3
Display
Component
{id: 2}
- 6. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ {id: 1} , {id: 2} ]
Component-2
Component-1
Component-3
Display
Component
- 7. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
Component-2
Component-1
Component-3
Display
Component
{id: 1}
{uid: 3}
{id: 2},itemList: [ {id: 1} , {id: 2} ]
- 8. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
itemList: [ {id: 1} , {id: 2} , { uid: 3} ]
Component-2
Component-1
Component-3
Display
Component
- 9. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
Component-2
Component-1
Component-3
Display
Component
{id: 1} {id: 2} , { uid: 3}itemList: [ {id: 1} , {id: 2} , { uid: 3} ]
- 10. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Why Redux
Component-2
Component-1
Component-3
Display
Component
itemList: [ {id: 1} , {id: 2} , { uid: 3} ]
- 11. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Problems
• Hard to identify component with wrong logic.
• Need rework to see intermediate state of app.
• What if 100s of component updating same complex data.
• Passing data through long chain of nested components.
• Problems due to data mutation takes hours to debug and
then finally you realize the issue and you are like ….
- 12. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store
- 13. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Store
• Store is nothing but simple
javaScript object which
holds application
state/data.
Store State
- 14. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
• What is store state.
• Single instance of store will be used throughout
application.
- 15. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store
- 16. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store Action1
- 17. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Action
- 18. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store Action1
- 19. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store's
state-1 Action1
Store's state1
Action1
- 20. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store
state-1 Action2
Store's state1
Action1
- 21. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store's
state-2 Action2
Store's state1
Action1
Store's state2
Action2
- 22. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store's
state-2 Action3
Store's state1
Action1
Store's state2
Action2
- 23. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux
Component-2
Component-1
Component-3
Display
Component
Store's
state-3 Action3
Store's state1
Action1
Store's state2
Action2
Store's state3
Action3
- 24. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Reducer
• Reducer is just a function
which understands action
that components raise or
dispatches.
• It is responsible for taking
out payload/data from
action and appropriately
storing it in redux store.
• You will write actions as
well as reducer
24
- 25. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Redux data
flow
25
Credits: Medium.com
- 26. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Demo ...
Vanilla Redux
- 27. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Any Questions
- 28. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
You might not need redux ...
- 29. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
React Redux
• Connect api helps application to connect with redux
store.
• It creates wrapper component around our component
• It avoids some grunt work
– like subscribing to store in each component.
– Import store and passing dispatch to every component
– Optimization to avoid unnecessary re-renders when store
changes.
- 30. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Demo ...
React Redux
- 31. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Connect api code
- 32. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Cross Slice Reducer …
- 33. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
- 34. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Multiple stores
- 35. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Normalized Store
- 36. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Normalized Store
- 37. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Chrome Plugin
Demo ...
- 38. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Replace Reducer
- 39. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Replace Reducer
- 40. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Hot reloading for faster
development
- 41. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Preloaded state
- 42. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
- 43. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Most Important, Interesting and
Easy part of Redux.
- 44. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Middleware
Credits: tenor.com
- 45. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Let's see how middleware works.
Syntax is available on docs as well.
- 46. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Component dispatches
action
Middleware 1 Middleware 2 Middleware 3
Reducer
Action
Action Action
Action
- 47. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Demo ...
- 48. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights
Thunk Middleware
- 49. Copyright © 2018 Talentica Software (I) Pvt Ltd. All rightsCopyright © 2018 Talentica Software (I) Pvt Ltd. All rights