Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Sync Vue.js Components with Streaming Content using $watchAsObservable and RxJS

    John LindquistJohn Lindquist

    Syncing UI and Content is a common scenario. This lesson show how clicking on a tab can load data into a container and keep the selected tab and the data inside the container in sync.

    vueVue.js
    ^2.0.0
    rxjsRxJS
    ^5.0.0
    javascriptJavaScript
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:01 I'm going to refactor out these buttons and move that behavior into these tabs. Something I'll need to do for that is to create an array of people. That's just objects of names, so Luke, an ID of 1, then Darth and Leia. Darth as an ID of 4, and Leia has an ID of 5.

    00:26 Now I can pass these people into my tabs. I'll get rid of these. I can v4 on these tab items. I'll say person of people. I can key that against the person.ID, and the label will now be bound to person.name. Hit Save there, and there's no visual change, it's just updated to use my set of data.

    00:53 In fact, let's throw in Yoda for good measure just to show him. 20 and Yoda. Now we have a Yoda tab. To make sure we load the right person, I'll have to map the active tab IDs to the IDs in our people. That'll look something like removing this .click and saying active tab map. This is the tab ID.

    01:19 We want to select this .people tab ID.ID. This ID will find the person and .ID will find this ID. Now with that simple refactor, I hit Save and everything updated perfectly. Hit Darth, click Leia, click Yoda, and everything's working because I simply swapped that click stream for an active tab stream...

    Discuss

    Discuss