Riot JS - Getting Started with this React-like micro-library

Tim Kindberg
InstructorTim Kindberg
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 5 years ago

Getting started with Riot JS. We'll discuss riot's compile and mount process and build a small hello world component with simple data-binding.

[00:01] Riot.js is a micro framework. It's only three and a half kilobytes. With it you get custom tags, eventing, and rounding, that's all. Otherwise it just gets out of your way and lets you code. I was able to learn the entirety of Riot.js in about two days, one day to read the docs, and one day to write a small app. The ability to get started quickly, and for such a small size is why I think Riot could become a very popular framework.

[00:27] Let's see how we get started with riot. I'll make a simple "Hello World" example. You'll have to download the proper files. There is a riot.js file and a compiler.js file. The riot.js file houses the framework APIs while the compiler.js files houses the capability of turning Riot syntax into JavaScript syntax. The beauty of riot's compiler is how fast it is, which means you can precompile your files or you can let them compile at runtime. It's not even unreasonable to do runtime compiling in production.

[01:03] Let's grab the minified combo file which contains both the framework and the compiler. I've already added it to my project over here. Now I need to create a Riot component file. Riot files end with .tag. This .tag file will compile to regular JavaScript at runtime. To declare a custom tag, simply write it out without indent. In here, Riot expects your component to have your HTML on top and the JavaScript on bottom. For databinding, use single curly braces. Everything between the braces is just regular JavaScript.

[01:51] This is implied, so I don't have to write this.what, I can just write what. I'll add my file to my index file as a script of type = Riot/tag. You also have to explicitly mount any custom tag used outside of a .tag file. For example, here in the body of my index. You just say riot.mount and then you can pass a * if you want to mount every custom tag on the page, or you can pass in specific tags.

[02:27] Now I'm free to use my Hello World component in my index file. When I refresh, you'll see that we've successfully created a simple Riot component, complete with databinding and runtime compilation.

egghead
egghead
~ 2 hours 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