Build an observable from a simple english requirement

Rares Matei
InstructorRares Matei
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Having built all the event streams we need, we can now assemble them and generate the observable equivalent of our main requirement sentence: “When the loader needs to show, show the loader, until it’s time to hide it”.

Instructor: [00:00] We started from some very low-level terms like task starting or ending and we went up our floors tackling one small problem at a time creating higher- and higher-level abstractions that eventually brought us to being able to solve our top-level requirement. We now have all the pieces we need for this. Let's go and assemble it.

[00:19] I'll add the comment for this new layer as well. When the spinner needs to show, show the spinner. Remember, we consider this to be an observable that when activated shows the spinner. We're not going to worry yet about how that's going to work.

[00:35] When a task starts, switch to displaying the spinner until, and I'll pipe this to our take until, until it's time to hide it. We don't really care what or when this observable emits. This is meant to be a top-level overview of how everything is wired up. We don't really need to reuse it, but we do want to activate it. I'll just subscribe to it in here.

[01:02] The moment somebody imports this file, this observable will be activated. Yes, it will live on for the duration of our app. We never unsubscribe from it. But that's something we're OK with because we do want this to keep tracking tasks for the lifetime of our app.

[01:16] To recap, we've marked our low-level building blocks and we kept assembling them into more powerful building blocks. We also made sure not to dump everything in the same stream and instead obstruct the obstructions that make sense on their own.

[01:32] Not only does this keep our RxJS code more readable, almost flowing like an English sentence, but it also allows us to reuse some of these should we need to do so later, and we will need to.

egghead
egghead
~ 10 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today