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
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
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
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
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
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
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)