Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Meet Riot.js @ SnowCamp.io

ctranxuan
January 21, 2016

Meet Riot.js @ SnowCamp.io

Dive with us in the exploration of Riot.js, a micro-UI JS library. Micro but powerful! Simplicity and modularity are the motto of this great lib!

ctranxuan

January 21, 2016
Tweet

More Decks by ctranxuan

Other Decks in Programming

Transcript

  1. What is Riot.js? What is Riot.js? A micro UI library

    A micro UI library « à la React » « à la React » « à la Polymer » « à la Polymer » ( ( ) )
  2. « À la Polymer » « À la Polymer »

    custom tags custom tags <my-tag></my-tag> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <my-tag></my-tag> </body> </html>
  3. Custom tag Custom tag « web component » « web

    component » html code (layout) js code (behavior) = = + + css code (style)
  4. Custom tag Custom tag <!doctype html> <html lang="en"> <head> <meta

    charset="utf-8"> <title>Hello World</title> </head> <body> <hello-world></hello-world> <!-- include riot.js --> <script src="./riot.min.js"></script> <script src="./hello-world.js"></script> <script> riot.mount('hello-world', { title: 'Say hello!'}); </script> </body> </html>
  5. <hello-world> <h3>{opts.title}</h3> <input name="helloInput" placeholder="Enter your name"> <button class="myButton" onclick="{

    sayHello }">Say Hello</button> <h4>{message}</h4> </hello-world> <hello-world> <h3>{opts.title}</h3> <input name="helloInput" placeholder="Enter your name"> <button class="myButton" onclick="{ sayHello }">Say Hello</button> <h4>{message}</h4> <script type='text/es6'> this.message = '' this.sayHello = (e) => { this.message = 'Hello ' + this.helloInput.value + '!' }; </script> </hello-world> Custom tag Custom tag hello-world.tag <hello-world> <h3>{opts.title}</h3> <input name="helloInput" placeholder="Enter your name"> <button class="myButton" onclick="{ sayHello }">Say Hello</button> <h4>{message}</h4> this.message = '' this.sayHello = (e) => { this.message = 'Hello ' + this.helloInput.value + '!' }; </hello-world> <hello-world> <h3>{opts.title}</h3> <input name="helloInput" placeholder="Enter your name"> <button class="myButton" onclick="{ sayHello }">Say Hello</button> <h4>{message}</h4> <script type='text/es6'> this.message = '' this.sayHello = (e) => { this.message = 'Hello ' + this.helloInput.value + '!' }; </script> <style> … </style> </hello-world>
  6. Eventing Eventing var myObs = riot.observable(); function Duck() { //

    Make Duck instances observable riot.observable(this); }
  7. Eventing Eventing // Send an event: myObs.trigger('myEvent', data); // Receive

    an event: myObs.on('myEvent', function(data) { // your code here });
  8. Routes Routes http:/ /myapp/#users/123/profile http:/ /myapp/#users/123/profile // register a callback

    route handler riot.route(function(part1, ..., partn) { // add your logic here });
  9. Routes Routes http:/ /myapp/#users/123/profile http:/ /myapp/#users/123/profile var routeCxt = riot.route.create();

    routeCxt('/users', function(part1, ..., partn) { // add your logic here }); Subroutes Subroutes
  10. What is Riot.js? What is Riot.js? View (custom tags) View

    (custom tags) Events Events Router Router
  11. Goodies: Mixins Goodies: Mixins // Somewhere... var LogMixin = {

    log: function(msg) { console.log(msg); } } // In the tag definition <my-tag> <h1>{ opts.title }</h1> this.mixin(LogMixin) ... this.log("Hello World!") </my-tag>
  12. Goodies: Mixins Goodies: Mixins // Somewhere in the space... var

    EventBusMixin = { observable: riot.observable() }; // Into the tag <my-tag> <h1>{ opts.title }</h1> this.mixin(EventBusMixin) ... this.observable.trigger('my event'); this.observable.on('my other event', doSomeStuff()); </my-tag>
  13. Summary Summary Riot.js = custom tags Riot.js = custom tags

    + events + events + router + router modularity + re-use modularity + re-use loose-coupling loose-coupling + modularity + modularity easy navigation easy navigation + goodies... + goodies...