课程: JavaScript: Five Advanced Challenges and Concepts
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
The basic Reactive pattern - JavaScript教程
课程: JavaScript: Five Advanced Challenges and Concepts
The basic Reactive pattern
- [Instructor] The core of a reactive pattern in JavaScript is a standalone ReactiveObject class managing and updating observers or subscribers. In the previous chapter, we bundled all the observer functionality into the main class. This time, we're extracting them to make the overall code more manageable and extensible. So this ReactiveObject class here is generic, and we use it anytime we want to create an observable class that we can then have subscribers subscribe to. You'll notice there's no real definition of any callbacks or any functions. Instead, we just have the subscribe, unsubscribe, and update functionality packaged inside the ReactiveObject. So how do this work? Well, in the exercise files, I've built out a fully functioning example so you can take a look for yourself. We start out by creating a temperature monitoring object. So this is just a regular temperature monitor. The TemperatureMonitor extends the…