Fireship · @fireship
NGXS - Angular State Management
Uploaded April 10, 2018 · Length 12:00
Summary
A comparison of NGXS and NgRx state management libraries for Angular, focusing on the basics of NGXS and its benefits over NgRx.
- ngxs vs ngrx
- angular state management
- ngxs tutorial
- state management libraries
- angular development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:01
today we're going to take a look at ng
- 0:04
XS a new state management library that
- 0:06
reimagines the way the Redux pattern
- 0:08
should be applied and angular it gives
- 0:11
us a global and mutable data store then
- 0:13
components can select data from the
- 0:15
store as an observable then dispatch
- 0:17
actions to mutate the store the end
- 0:20
result is a circular predictable flow of
- 0:22
data that is especially beneficial for
- 0:24
apps that have a complex data state in
- 0:27
this episode we'll go through the basics
- 0:29
of ng XS from the ground up if you're
- 0:31
new make sure to LIKE and subscribe and
- 0:33
grab the full source code from angular
- 0:34
firebase comm so first we need to
- 0:37
address the elephant in the room there's
- 0:39
already a state management library for
- 0:41
angular called ng R X which has become
- 0:43
very popular by taking the
- 0:45
implementation details of react Redux
- 0:47
and applying them to angular but the
- 0:50
problem is that angular has a type
- 0:51
system and makes heavy use of
- 0:53
object-oriented programming while react
- 0:55
has no type system and makes heavy use
- 0:57
of pure functions in order to strong
- 0:59
type everything and maintain a strict
- 1:01
separation of concerns and ng Rx we have
- 1:03
to write a ton of boilerplate code code
- 1:06
that is often very difficult to read
- 1:07
especially for someone without an rxjs
- 1:10
background while I'm a big fan of ng rx
- 1:12
and one of its top donors I think ng XS
- 1:15
addresses some of these concerns in a
- 1:17
very elegant way so what I've done for
- 1:19
this video is I built an app with ng XS
- 1:22
and then I built the same exact app with
- 1:24
ng Rx so we can compare them
- 1:25
side-by-side
- 1:26
the rest of this video will focus on the
- 1:29
basics of ng XS but occasionally I'll
- 1:31
flip over to this ng rx app just so you
- 1:33
can see that differences and how the
- 1:35
code is implemented and I'm not
- 1:37
recommending one over the other just
- 1:38
showing you a comparison between the two
- 1:40
the app itself is called ng XS salad bar
- 1:44
and it allows the user to create and
- 1:46
customize a salad order if you look at
- 1:49
the UI here you'll see everything
- 1:50
highlighted in green is saved in the app
- 1:52
store and everything with a solid
- 1:55
outline border is triggering an action
- 1:57
so you can see here we trigger actions
- 1:59
that add toppings to the salad and then


