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