Use an RxJS Observable in Svelte

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Svelte can easily import RxJS and use all the Observables available fairly intuitively. Once you create your new Svelte project, simply install RxJS, create Observables as you would normally, then reference the Observable inside of your HTML with the $ binding to subscribe to it.

This lesson walks you through the process of using an RxJS interval with Svelte by importing RxJS, then creating an interval Observable which we use inside of the template.

Instructor: [0:00] I created a new Svelte app from the default template. We will install RxJS. Inside of our script tag, we can import anything from RxJS. I will import interval. Then I can create a variable called timer, and create a new interval that will fire every one second.

[0:21] All that's left to do inside of our HTML is to use the Svelte bindings to reference our variable, which is an observable. Hit save, and you'll see our timer will start counting.

[0:35] We can also import any of the operators. I want to import the map operator from RxJS/operators. That way, I can pipe the interval into a map, which will take the value and multiply it by two. Now when I hit save, you'll see each value will be multiplied by two.

egghead
egghead
~ 47 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today