SlideShare a Scribd company logo
Dumb and smart
components & redux
Brecht Billiet
About me
Brecht Billiet
Frontend Architect - Coach - Trainer
http://brecht.io @brechtbilliet
Who still uses ng-
controller and ng-
include?
Doesn’t that bother you?
● What HTML belongs to what JS?
● Where do the templates live?
● Absolute template-paths are not maintainable
● What logic belongs in a controller or directive?
● This template should contain... oh wait, there is an ng-include there.
● How do you pass data to your controllers?
Think in components...
● 1 piece HTML + 1 piece LOGIC = COMPONENT
● You know it as: element directives
● Custom DOM tags
● A component has a single responsability
● We could use webcomponents + shadow DOM
● Sandboxed work
● Note: angular 1.5 has new component syntax
What should you
refactor to
components?
Dumb and smart components + redux (1)
Everything is a component
● Your application is a tree of components
● Your pages are components
● Even your application is a component
application
Html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
application
Html + js
+ css
fooPage
html + js
+ css
html + js
+ css
barPage
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
html + js
+ css
Routingconfig:
template: ‘<foo-page/>’
Routingconfig:
template: ‘<bar-page/>’
Easier to debug
Other advantages
● No scope soup
● Nice hierarchy view
● Single responsability
● No more absolute paths
● Easier to reason about
● Easier to refactor
● Easier to upgrade to ng2
What about attribute-directives?
● Let’s call them behaviors from now
● They add some logic to existing or custom components
● Separate them from your components folder
DEMO
http://winecellar.surge.sh
http://winecellar.surge.sh: components
Any rules of thumb?
Dumb and smart components + redux (1)
Keep them small...
Keep them dumb where possible...
Dumb component Smart component (container)
Doesn’t know about the
application
Knows about the application
Doesn’t do data fetching Does data fetching
Main purpose is visualization Interacts the application
Reusable Not reusable
Only communicates with its direct
parent
Passes state and data to its
children
Doesn’t do state management Does state management
http://winecellar.surge.sh: Smart
components
http://winecellar.surge.sh: Dumb
components
State management
● State is very hard to manage in SPA’s
● State can be
○ data: results from REST calls
○ “sidebar is collapsed” or “spinner is active”
○ Which tab is currently active
State management
● 3 types of state
○ Data state
○ Application state
○ Inner state (e.g value of textbox) We don’t have to persist nor manage that
Why is it so hard to manage?
● 1-way databinding and 2-way databinding
● javascript references that are being broken and sometimes kept
● We can mutate the data in a million different ways
● No structure
● Data flows in different directions
application
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
state &
logic
Without flux
1
2
5 6
3
7 8
4
9
10 11
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
I’m sending
an event
upwards
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
I’m sending
an event
upwards
I’m sending
events
downwards
Without flux
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
I’m sending
an event
upwards
Without flux
I’m sending
events
downwards
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
I’m sending
an event
upwards
I get my data
from model x
and I can
update it
here
I get my data
from model z
Without flux
I’m sending
events
downwards
I get my data
from model y
1
2
5 6
3
7 8
4
9
10 11
I changed
So did I
My changes
should
reflect 6 and
4
I have to
subscribe
before 8
sends a
message
I’m sending
an event
upwards
I get my data
from model x
and I can
update it
here
I get my data
from model z
Without flux
My data is
passed by
twoway
binding
I’m sending
events
downwards
I get my data
from model y
My data is
passed by
oneway
binding
My data is
passed by
twoway
binding
Where do those states/events come from?
Who updated my state??
Who updated/notified which component?
Dumb and smart components + redux (1)
Flux helps with that
● Brings structure in data flow
● Not a framework but an architecture by facebook
● Unidirectional dataflow, oneway databinding
● Data flows from the top down
● Easier to reason about state
● Action
○ Has an action type and a payload
● Dispatcher
○ Dispatches the actions to the store
● Store
○ Contains state
● View
Components
● The unidirectional dataflow makes it easy to reason about
I use Redux!
Redux is based on
flux, but it’s easier
Redux
● Written by Dan Abramov (Facebook)
● Easier to use and less bloat
● Only has one store!!
● Completely Immutable data structure
● Uses reducers (pure functions)
● Flux approves
1
2
5 6
3
7 8
4
9
10 11
STORE
1
2
5 6
3
7 8
4
9
10 11
Me too
Me too
Me too
Me too
STORE
I only send
actions
upwards to the
store
I’m the single-
source-of-truth
in your
application!! ;-)
1
2
5 6
3
7 8
4
9
10 11
Me too
Me too
I’m dumb I’m dumb
I’m dumb I’m dumb
I’m dumb
I’m dumb
STORE
Me too
I only send
actions
upwards to the
store Me too
I’m the single-
source-of-truth
in your
application!! ;-)
Dumb components only
notify their direct parents!
No state management
needed here :-)
What’s different?
● We have one single source of truth: the store
● We don’t update state ourselves anymore, the store handles all the state of
our application
● State is immutable
● Actions are always sent upwards
What’s different?
● Dumb components don’t do state management
● State is being updated by pure functions (reducers)
● When the store is updated it notifies all the smart components
Application state
Actions
● Actions have a type and a payload
● Keep the types together, gives clear overview
Actions
Reducers
● Pure functions
● reducer(state: MyState, action: Action): MyState
● they update the state
● Completely immutable
Reducers
Example in container
Middleware
● Easy logging, debugging
● Reproducible action state (pushable to server)
● Timetraveling with redux-devtools (requires react to be bundled in the
angular project)
Check it out
● egghead.io course (Free)
○ https://egghead.io/series/getting-started-with-redux
Special thanks to
● Kwinten Pisman (@kwintenp)
● Jurgen Van de Moere (@jvandemo)
Questions?
One more thing
Angular2, rxjs, redux,
@ngrx/store, Typescript,
webpack
http://workshop.brecht.io @brechtbilliet
Workshop
June 2016
Thank you!

More Related Content

PPTX
Agular in a microservices world
PDF
Migrating a large scale banking app to compose
PPTX
Scaling automated quality text generation for enterprise sites
PDF
Five Common Angular Mistakes
PPTX
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
PPT
Website Integration with QuickBase - Joshua McGinnis
PPTX
Query Classification on Steroids with BERT
PDF
Frontend as a first class citizen
Agular in a microservices world
Migrating a large scale banking app to compose
Scaling automated quality text generation for enterprise sites
Five Common Angular Mistakes
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Website Integration with QuickBase - Joshua McGinnis
Query Classification on Steroids with BERT
Frontend as a first class citizen

What's hot (19)

PDF
Let Codenarc check if you write good Groovy code
PPTX
Html 5 tutorial - By Bally Chohan
PDF
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
PDF
Write Once, Run Everywhere
PDF
Software Testing for SEO
PDF
Nitro for your Grails App: How to improve performance!! Greach' 18
PDF
Accessibility Report for training website
PPT
HTML5 with examples
PDF
Headless SEO: Optimising Next Gen Sites | brightonSEO 2021
PPTX
Behaviour Driven Development
PDF
What I learned teaching programming to 150 beginners
PDF
SEO Checklist for Google Mobile First Index
PPTX
2 Seconds is the New Slow - Chris Simmance - under2
PDF
Rich HTML5 Web Apps: Typesafe Edition
PPTX
Technical SEO "Overoptimization"
PPTX
The New Renaissance of JavaScript
PDF
React native - What, Why, How?
PPTX
TechSEO Boost 2018: The Statelessness of Technical SEO
PDF
The Great Migration: Moving Your SharePoint | Fpwebinar
Let Codenarc check if you write good Groovy code
Html 5 tutorial - By Bally Chohan
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
Write Once, Run Everywhere
Software Testing for SEO
Nitro for your Grails App: How to improve performance!! Greach' 18
Accessibility Report for training website
HTML5 with examples
Headless SEO: Optimising Next Gen Sites | brightonSEO 2021
Behaviour Driven Development
What I learned teaching programming to 150 beginners
SEO Checklist for Google Mobile First Index
2 Seconds is the New Slow - Chris Simmance - under2
Rich HTML5 Web Apps: Typesafe Edition
Technical SEO "Overoptimization"
The New Renaissance of JavaScript
React native - What, Why, How?
TechSEO Boost 2018: The Statelessness of Technical SEO
The Great Migration: Moving Your SharePoint | Fpwebinar
Ad

Viewers also liked (17)

PPTX
Redux in Angular2 for jsbe
PPTX
React + Redux Introduction
PPTX
Into the Land of lambda, One Programmer's Journey Into Functional Programming
PPTX
React. Flux. Redux. by Andrey Kolodnitskiy
PDF
Understanding Redux — Ilya Gelman
PDF
Application architecture doesn't have to suck
PDF
The evolution of redux action creators
PDF
Side Effects: Uma Saga até o React
PPT
'Did He Really Say That?" effective component communication
PPTX
React. Flux. Redux
PPTX
The redux saga begins
PDF
Angular 2 Component Communication - Talk by Rob McDiarmid
PDF
Simple made easy
PDF
RxJS + Redux + React = Amazing
PDF
Are we there yet?
PDF
Asyc flow control with javascript generators - redux-saga
PDF
UX Jam x UX Sketch 2017 HD
Redux in Angular2 for jsbe
React + Redux Introduction
Into the Land of lambda, One Programmer's Journey Into Functional Programming
React. Flux. Redux. by Andrey Kolodnitskiy
Understanding Redux — Ilya Gelman
Application architecture doesn't have to suck
The evolution of redux action creators
Side Effects: Uma Saga até o React
'Did He Really Say That?" effective component communication
React. Flux. Redux
The redux saga begins
Angular 2 Component Communication - Talk by Rob McDiarmid
Simple made easy
RxJS + Redux + React = Amazing
Are we there yet?
Asyc flow control with javascript generators - redux-saga
UX Jam x UX Sketch 2017 HD
Ad

Similar to Dumb and smart components + redux (1) (20)

PDF
Introduction to Redux (for Angular and React devs)
PDF
Redux in Angular 2+
PDF
Angular redux
PDF
The Road To Redux
PDF
Front end architecture patterns
PDF
Evan Schultz - Angular Summit - 2016
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
PDF
Redux with angular 2 - workshop 2016
PDF
ngSummit 2017: Angular meets Redux
PDF
Smart and Dumb Components
PDF
redux and angular - up and running
PDF
Predictable reactive state management - ngrx
PPTX
Reducers+flux=redux
PDF
Building React Applications with Redux
PPTX
Fluxish Angular
PDF
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
PPTX
React & redux
PDF
The State of Front-end At CrowdTwist
PDF
Redux js
PPTX
React.js at Cortex
Introduction to Redux (for Angular and React devs)
Redux in Angular 2+
Angular redux
The Road To Redux
Front end architecture patterns
Evan Schultz - Angular Summit - 2016
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Redux with angular 2 - workshop 2016
ngSummit 2017: Angular meets Redux
Smart and Dumb Components
redux and angular - up and running
Predictable reactive state management - ngrx
Reducers+flux=redux
Building React Applications with Redux
Fluxish Angular
Fabio Biondi - Front-end data architectures in Angular, Redux & NGRX - Codemo...
React & redux
The State of Front-end At CrowdTwist
Redux js
React.js at Cortex

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
System and Network Administration Chapter 2
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administraation Chapter 3
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Introduction Database Management System for Course Database
System and Network Administration Chapter 2
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Designing Intelligence for the Shop Floor.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Softaken Excel to vCard Converter Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
System and Network Administraation Chapter 3
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Internet Downloader Manager (IDM) Crack 6.42 Build 41
wealthsignaloriginal-com-DS-text-... (1).pdf
Reimagine Home Health with the Power of Agentic AI​
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle

Dumb and smart components + redux (1)

  • 1. Dumb and smart components & redux Brecht Billiet
  • 2. About me Brecht Billiet Frontend Architect - Coach - Trainer http://brecht.io @brechtbilliet
  • 3. Who still uses ng- controller and ng- include?
  • 4. Doesn’t that bother you? ● What HTML belongs to what JS? ● Where do the templates live? ● Absolute template-paths are not maintainable ● What logic belongs in a controller or directive? ● This template should contain... oh wait, there is an ng-include there. ● How do you pass data to your controllers?
  • 5. Think in components... ● 1 piece HTML + 1 piece LOGIC = COMPONENT ● You know it as: element directives ● Custom DOM tags ● A component has a single responsability ● We could use webcomponents + shadow DOM ● Sandboxed work ● Note: angular 1.5 has new component syntax
  • 6. What should you refactor to components?
  • 8. Everything is a component ● Your application is a tree of components ● Your pages are components ● Even your application is a component
  • 9. application Html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css
  • 10. application Html + js + css fooPage html + js + css html + js + css barPage html + js + css html + js + css html + js + css html + js + css html + js + css html + js + css Routingconfig: template: ‘<foo-page/>’ Routingconfig: template: ‘<bar-page/>’
  • 12. Other advantages ● No scope soup ● Nice hierarchy view ● Single responsability ● No more absolute paths ● Easier to reason about ● Easier to refactor ● Easier to upgrade to ng2
  • 13. What about attribute-directives? ● Let’s call them behaviors from now ● They add some logic to existing or custom components ● Separate them from your components folder
  • 14. DEMO
  • 17. Any rules of thumb?
  • 20. Keep them dumb where possible...
  • 21. Dumb component Smart component (container) Doesn’t know about the application Knows about the application Doesn’t do data fetching Does data fetching Main purpose is visualization Interacts the application Reusable Not reusable Only communicates with its direct parent Passes state and data to its children Doesn’t do state management Does state management
  • 24. State management ● State is very hard to manage in SPA’s ● State can be ○ data: results from REST calls ○ “sidebar is collapsed” or “spinner is active” ○ Which tab is currently active
  • 25. State management ● 3 types of state ○ Data state ○ Application state ○ Inner state (e.g value of textbox) We don’t have to persist nor manage that
  • 26. Why is it so hard to manage? ● 1-way databinding and 2-way databinding ● javascript references that are being broken and sometimes kept ● We can mutate the data in a million different ways ● No structure ● Data flows in different directions
  • 27. application state & logic state & logic state & logic state & logic state & logic state & logic state & logic state & logic state & logic state & logic Without flux
  • 28. 1 2 5 6 3 7 8 4 9 10 11 Without flux
  • 29. 1 2 5 6 3 7 8 4 9 10 11 I changed Without flux
  • 30. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I Without flux
  • 31. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 Without flux
  • 32. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message Without flux
  • 33. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message I’m sending an event upwards Without flux
  • 34. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message I’m sending an event upwards I’m sending events downwards Without flux
  • 35. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message I’m sending an event upwards Without flux I’m sending events downwards
  • 36. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message I’m sending an event upwards I get my data from model x and I can update it here I get my data from model z Without flux I’m sending events downwards I get my data from model y
  • 37. 1 2 5 6 3 7 8 4 9 10 11 I changed So did I My changes should reflect 6 and 4 I have to subscribe before 8 sends a message I’m sending an event upwards I get my data from model x and I can update it here I get my data from model z Without flux My data is passed by twoway binding I’m sending events downwards I get my data from model y My data is passed by oneway binding My data is passed by twoway binding
  • 38. Where do those states/events come from?
  • 39. Who updated my state??
  • 42. Flux helps with that ● Brings structure in data flow ● Not a framework but an architecture by facebook ● Unidirectional dataflow, oneway databinding ● Data flows from the top down ● Easier to reason about state
  • 43. ● Action ○ Has an action type and a payload ● Dispatcher ○ Dispatches the actions to the store ● Store ○ Contains state ● View Components
  • 44. ● The unidirectional dataflow makes it easy to reason about
  • 45. I use Redux! Redux is based on flux, but it’s easier
  • 46. Redux ● Written by Dan Abramov (Facebook) ● Easier to use and less bloat ● Only has one store!! ● Completely Immutable data structure ● Uses reducers (pure functions) ● Flux approves
  • 48. 1 2 5 6 3 7 8 4 9 10 11 Me too Me too Me too Me too STORE I only send actions upwards to the store I’m the single- source-of-truth in your application!! ;-)
  • 49. 1 2 5 6 3 7 8 4 9 10 11 Me too Me too I’m dumb I’m dumb I’m dumb I’m dumb I’m dumb I’m dumb STORE Me too I only send actions upwards to the store Me too I’m the single- source-of-truth in your application!! ;-) Dumb components only notify their direct parents! No state management needed here :-)
  • 50. What’s different? ● We have one single source of truth: the store ● We don’t update state ourselves anymore, the store handles all the state of our application ● State is immutable ● Actions are always sent upwards
  • 51. What’s different? ● Dumb components don’t do state management ● State is being updated by pure functions (reducers) ● When the store is updated it notifies all the smart components
  • 53. Actions ● Actions have a type and a payload ● Keep the types together, gives clear overview
  • 55. Reducers ● Pure functions ● reducer(state: MyState, action: Action): MyState ● they update the state ● Completely immutable
  • 58. Middleware ● Easy logging, debugging ● Reproducible action state (pushable to server) ● Timetraveling with redux-devtools (requires react to be bundled in the angular project)
  • 59. Check it out ● egghead.io course (Free) ○ https://egghead.io/series/getting-started-with-redux
  • 60. Special thanks to ● Kwinten Pisman (@kwintenp) ● Jurgen Van de Moere (@jvandemo)
  • 62. One more thing Angular2, rxjs, redux, @ngrx/store, Typescript, webpack http://workshop.brecht.io @brechtbilliet Workshop June 2016