Check out a free preview of the full Enterprise Architecture Patterns course

The "Observables Examples and Q&A" Lesson is part of the full, Enterprise Architecture Patterns course featured in this preview video. Here's what you'd learn in this lesson:

Lukas answers questions about currying, partially applied functions, and Redux vs. Observables.

Preview
Close

Transcript from the "Observables Examples and Q&A" Lesson

[00:00:00]
>> Where are you doing the currying they're asking on the example?
>> So, on the scan, let me come back to the code And [COUGH] Let me pull this up. So for the record, I'm not doing currying, I'm doing partial application. It's a little bit different. Right here.

[00:00:34]
So when this event comes in. Is that. It is returning this function right here. Which then because it doesn't have the position object just yet until it gets into the scan operator which once we hit the scan operator, then it's passing the position here. And so how you can know that I'm doing this is that how I'm partially applying the function is that if we go down here Increment and decrement they have three properties and over here, I am satisfying two of them.

[00:01:30]
And what that does is it returns a new function that I can then call and execute by only passing in a single parameter because the other two are supplied. And so this is where this is happening right here is that I'm partially applying it by satisfying these two parameters, but it doesn't get executed.

[00:01:58]
Until we get down to here. Hopefully, I realize on one hand is this is kind of an advanced JavaScript function, but that is where that's happening. And [LAUGH] I would say if this is interesting, what I had to do, I'm just being completely candid that I had to really spend, I would say a good maybe at least an afternoon and afternoon wrapping my mind around this.

[00:02:33]
What I can do is this mark does your chat except markdown down by any chance.
>> Yeah.
>> Cool.
>> Basic markdown.
>> Yep. Several marked out. So give me one second here and I'm going to just produce an example in effect. I don't think there's anything sensitive about this at all.

[00:03:03]
So I can go ahead and share it. And I'll go ahead and put this in the chat room. Just so we can surface this as an example. But this is. Me attempting to wrap my mind around how this works. So I would give this a look and this is a pretty good example of how we can use partial application functions to do some interesting things.

[00:03:45]
Where it gets really interesting is if you go down here, the stuff that I'm doing with dash title, title case camel case so not intended to get pulled off into destruction but check this example out. And with that said, let's move on to the next question.
>> I think one person was kind of confused on where the lines between Redux and observables, like where does each of those libraries cannot come into play?

[00:04:17]
>> Yeah, so the question is, what is better observables or Redux? And the answer is that, they're really two separate abstraction layers, is that, you can use observables what I consider for like micro state management of that I want to communicate a single event and I want to manage it.

[00:04:43]
Redux is good for large scale, application state management. And in fact, if you're using like NGR x that it's Redux, with an observable or behavior subject under the hood and so that it's not typically one or the other. It comes down to what abstraction layer, are you trying to solve that complexity.

[00:05:08]
So observables are great for communicating very specific things and managing, state run those specific things at a very micro level. As you can see, we're doing this at the interaction level. But Redux is really for managing state at the application level. So the answer is, one is not better than the other.

[00:05:32]
In fact, one actually, in the case of Vinci RX uses the other to do all of its heavy lifting. The request is regarding immutables. I'd love to hear a short recap on a reference comparison to react. Well, again, we're comparing two entirely separate things is that really immutable operations and the techniques that we use to achieve immutability exist in React or Angular.

[00:06:01]
So, the frameworks and the implementation of immutable operations are at the language level. And so, what's interesting is that the immutable operations that I use in these examples, and so I realized we're using kind of angular as the shell, but I actually learned these from 10 Abraham off, who was coding in React.

[00:06:28]
So a lot of what I've shown you very, very little of this is, I would say Angular specific at all. The only reason why we even have in this case Angular is so that we can see some of the stuff in the browser to kind of give it some more context but Immutable operations are not framework specific.

[00:06:52]
Ramda immutable js not framework specific, observables not framework specific and TypeScript, also not framework specific. And so this is what I think is really cool. And why I was super excited to do this workshop is that even though we have a little bit of Angular in here what we've really done is we've pulled out, the things that you can use no matter what type script being a big one and apply that to anything and apply these techniques to anything.

[00:07:23]
So not only are we talking about the techniques, but hopefully, we started to see some of the mental models and some of the things that we can use to think about programming in general. So, the iron triad of managing state, flow control and code volume, then the access of evil with hidden state nested logic and the single responsibility principle violations, and then the four elements of programming being nouns, verbs, conditions, and iterators.

[00:07:58]
And then kind of that fifth element of how do we manage time within the context of our application, and this is where I believe observables does this better than anybody. And using because I did make the claim and I stand by it is everything that I do can fit on a single piece of paper.

[00:08:22]
And that's it is that is the simple patterns that I use to put together, to build into larger, large scale enterprise applications.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now