⚠️ This lesson is retired and might contain outdated information.

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

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet

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.

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...