• Complain

it-ebooks - Rxjs 5 ultimate

Here you can read online it-ebooks - Rxjs 5 ultimate full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: iBooker it-ebooks, genre: Romance novel. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

it-ebooks Rxjs 5 ultimate
  • Book:
    Rxjs 5 ultimate
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2018
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Rxjs 5 ultimate: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Rxjs 5 ultimate" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote Rxjs 5 ultimate? Find out the surname, the name of the author of the book and a list of all author's works by series.

Rxjs 5 ultimate — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Rxjs 5 ultimate" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Table of Contents
  1. Starting out
  2. 1.1
  3. 1.2
  4. 1.3
  5. 1.4
  6. 1.5
  7. Observables
  8. 2.1
  9. 2.2
  10. 2.3
  11. 2.4
  12. 2.5
  13. 2.6
  14. Operators
  15. 3.1
  16. 3.2
  17. 3.3
  18. 3.4
  19. 3.5
  20. 3.6
  21. 3.7
  22. 3.8
  23. 3.9
  24. 3.10
  25. 3.11
  26. Recipes
  27. 4.1
  28. 4.2
  29. 4.3
  30. 4.4
  31. Advanced
  32. 5.1
  33. 5.2
  34. Appendices
  35. 6.1
  36. 6.2
  37. 6.3
Appendix I - ngrx
ngrx
Appendix II - build your own Rxjs
Build your own RxJS

To truly understand Rxjs I recommend trying to implement a subset of it yourself just to see what kind of code you produce. For most cases it isn't really necessary to understand on that depth but do try it if you got some time over. Let's look at what a really basic implementation can look like and refactor it slowly into something that looks like the real thing.

Step I
Step II
Step III
Step IV
book.json
Cascading calls
Cascading calls

A cascading call means that based on what call is happening another call should take place and possibly another one based on that.

Dependant calls

A dependant call means the calls needs to happen in order. Call 2 must happen after Call 1 has returned. It might even be possible that Call2 needs be specified using data from Call 1.

Imagine you have the following scenario:

  • A user needs to login first
  • Then we can fetch their user details
  • Then we can fetch their orders
Promise approach
login() .then(getUserDetails) .then(getOrdersByUser)
Rxjs approach
let stream$ = Rx.Observable.of({ message : 'Logged in' }) .switchMap( result => { return Rx.Observable.of({ id: 1, name : 'user' }) }) .switchMap((user) => { return Rx.Observable.from( [ { id: 114, userId : 1 }, { id: 117, userId : 1 } ]) })stream$.subscribe((orders) => { console.log('Orders', orders);})// Array of orders

I've simplied this one a bit in the Rxjs example but imagine instead of

Rx.Observable.of()

it does the proper ajax() call like in

Semi dependant
  • We can fetch a users details
  • Then we can fetch Orders and Messages in parallell.
Promise approach
getUser() .then((user) => { return Promise.all( getOrders(), getMessages() ) })
Rxjs approach
let stream$ = Rx.Observable.of({ id : 1, name : 'User' })stream.switchMap((user) => { return Rx.Observable.forkJoin( Rx.Observable.from([{ id : 114, user: 1}, { id : 115, user: 1}], Rx.Observable.from([{ id : 200, user: 1}, { id : 201, user: 1}]) )})stream$.subscribe((result) => { console.log('Orders', result[0]); console.log('Messages', result[1]);})
GOTCHAS

We are doing switchMap() instead of flatMap() so we can abandon an ajax call if necessary, this will make more sense in

Async code
Async code

Async code is code that isn't done immediately when being called.

setTimeout(() => { console.log('do stuff');}, 3000 )

3s seconds in the future the timeout is done and do stuff is echoed to the screen. We can see that the anonymous function we provide is being triggered when time has passed. Now for another more revealing example:

doWork( () => { console.log('call me when done');})function doWork(cb){ setTimeout( () => { cb(); }, 3000)}

Other example of callback code are events here demonstrated by a jQuery example

input.on('click', () => {})

The gist of callbacks and async in general is that one or more methods are invoked sometime in the future, unknown when.

The Problem

So we established a callback can be a timer, ajax code or even an event but what is the problem with all that?

One word Readability

Imagine doing the following code

syncCode() // emit 1syncCode2() // emit 2asyncCode() // emit 3syncCode4() // emit 4

The output could very well be

1,2,4,3

Because the async method may take a long time to finish. There is really no way of knowing by looking at it when something finish. The problem is if we care about order so that we get 1,2,3,4

We might resort to a callback making it look like

syncCode()syncCode()2asyncCode(()= > { syncCode4()})

At this point it is readable, somewhat but imagine we have only async code then it might look like:

asyncCode(() => { asyncCode2(() => { asyncCode3() => { } })})

Also known as callback hell, pause for effect :)

For that reason promises started to exist so we got code looking like

getData() .then(getMoreData) .then(getEvenMoreData)

This is great for Request/Response patterns but for more advanced async scenarios I dare say only Rxjs fits the bill.

Error handling
Error handling

There are two major approaches how to handle errors in streams. You can retry your stream and how it eventually will work or you can take the error and transform it.

Retry - how bout now?

This approach makes sense when you believe the error is temporary for some reason. Usually shaky connections is a good candidate for this. With a shaky connection the endpoint might be there to answer like for example every 5th time you try. Point is the first time you try it might fail, but retrying x times, with a certain time between attempts, will lead to the endpoint finally answering.

retry

The retry() operator lets us retry the whole stream, value for value x number of times having a signature like this :

retry([times])

The important thing to note with the retry() operator is that it delays when the error callback is being called. Given the following code the error callback is being hit straight away:

let stream$ = Rx.Observable.of(1,2,3).map(value => { if(value > 2) { throw 'error' }});stream$.subscribe( data => console.log(data), err => console.log(err))

The stream effectively dies when the error callback is being hit and this is where the rety() operator comes in. By appending it like so:

let stream$ = Rx.Observable.of(1,2,3).map(value => { if(value > 2) { throw 'error' }})retry(5)

This will run the sequence of values 5 more times before finally giving up and hitting the error callback. However in this case, the way the code is written, it will just generate 1,2 five times. So our code isn't really utilizing the operator to its fullest potential. What you probably want is to be able to change something between attempts. Imagine your observable looked like this instead:

let urlsToHit$ = Rx.Observable.of(url, url2,url3);

In this its clearly so that an endpoint might have answered badly or not at all on your first attempt and it makes sense to retry them x number of times.

However in the case of ajax calls, and imagining our business case is shaky connections it makes no sense to do the retry immediately so we have to look elsewhere for a better operator, we need to look to

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Rxjs 5 ultimate»

Look at similar books to Rxjs 5 ultimate. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Rxjs 5 ultimate»

Discussion, reviews of the book Rxjs 5 ultimate and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.