HN user

jhusain

3 karma
Posts0
Comments3
View on HN
No posts found.

Interestingly enough, we actually return Observables. The model returns a Model Response, which inherits from Observable. It also adds a "then" method which returns a promise when called.

The primary advantage of using the Observable's "subscribe" method instead of "then" is that you can cancel a request. Netflix makes heavy use of this feature. For example when quickly browsing through titles, we may cancel the request for data that you are no longer looking at.

As a matter of fact, falcor returns a Model response which inherits from observable and adds a then() method to it. That means that you can also call subscribe. If you call subscribe, you can cancel the request using the subscription return from the subscribe method. If you call then, it returns a Promise.

Original Author here. I fixed the Firefox bug and merged a pull request to allow answers to be transferred to other browsers. I will add a Show All Answers button soon for folks who just want to browse.

rcfox: These exercises teach functional programming concepts, and that includes composition as it applies to the Observer pattern. I use RX but you could also use bacon JS or build your own lightweight Observable library. You should check out rx.lite.js which is a minimal subset of the library. As for your concerns about including a library, I urge you to reconsider if you can afford the extra download size. The Observer pattern is ubiquitous in software and you'll be amazed how versatile Rx is. At Netflix we use it on the server and client for a wide variety of different tasks. Rx has more than paid for itself 10 times over.