Check out a free preview of the full Advanced Asynchronous JavaScript course
The "Redux" Lesson is part of the full, Advanced Asynchronous JavaScript course featured in this preview video. Here's what you'd learn in this lesson:
Jafar takes a moment to review redux and note that the operators taught in the workshop can be used to solve a number of problems.
Transcript from the "Redux" Lesson
[00:00:00]
>> Jafar Husain: Anybody heard of Redux? I wanted to take a quick moment to talk about Redux super briefly. For those of you who haven't heard of Redux, it's just a way of managing state in an application. And it's a really well-written framework, I love it, I'm a big fan.
[00:00:16]
How fast do you think we could write Redux with observable? So Redux is basically a big scan operation. It's a scan that takes the current state, you create a subject of actions, every single time the UI kicks off an action, it just necks the subject. And then you just scan over all the actions and initialize that scan with the initial state of the app.
[00:00:39]
And then you provide a reduced function, like that function that takes two arguments, and you take the new action, the current state. And you admit a new state and you get a stream of states. So Redux just takes a stream of actions, probably a subject, scans over it, provides an initial state, and outputs a stream of states.
[00:00:59]
And then you just turn around and render those states. Let's take a little, let's take a look at an example of that because it's worth doing just to show how many concepts you can represent with observable. So I'm gonna go,
>> Jafar Husain: So this function takes the last state, the action.
[00:01:40]
>> Jafar Husain: And here, if the action type is increment, it returns,
>> Jafar Husain: Like so,
>> Jafar Husain: else if.
>> Jafar Husain: And now we take this actions, and we subscribe to it, and we get a state. And then React anyway, those of you who know React, you can render some app component and state.
[00:02:34]
Does that make sense? Or I could go, better yet,
>> Jafar Husain: For those React guys in the room. That's basically all Redux is at its core, right, that's not to take anything away from Redux. It actually has a great set of development tools associated with it, and it's got a lot of nice features, and a lot of libraries out there.
[00:02:54]
So I'm not suggesting you don't need Redux and you can replace it with ten lines of RX. I'm more just making the point that fundamentally the operators you guys have learned today are so flexible and so abstract that you can apply them to solve a huge number of problems.
[00:03:07]
So there is Redux in a page with observable.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops