ikki
An extention toolkit for Riot.js.
Features
- passing promises/generators to the components instead of simple values
- routing inside the html w/o JavaScript
- simple controller class (not yet)
Getting started
To use ikki, Riot v2.1.0 or above is needed.
1) Install Riot and ikki
Use script tag:
or, via Browserify:
$ npm install --save ikki
var riot =
2) Introduce mixin to your tag
{ opts.message || 'Well...' } { opts.desc || 'Loading...' }
Guide
opts attribute
ikki provides opts
attribute to the component via mixin. It makes possible to:
- Pass objects to the component
- Pass promise to the component
- Pass generators to the component
Without ikki we used to write like this:
With ikki we can write this:
Also it's OK to pass the promise.
And genrators, too. Now that, we can separate views and controllers easily.
HTML router
The easiest way to write the routing of your Riot applications. No need to write JavaScript.
Patterns
/
: slash(/) matchs url without hashabc
: matchs exact 'abc'aaa/bbb/ccc
: matchs exact 'aaa/bbb/ccc'aaa/:xxx
: matchs anything starting with 'aaa/' and you can get the value of:xxx
by$xxx
*
: matchs any url
Redirects
- If redirect attribute is set, url will change to it
- CAUTION: don't make the infinite loop of redirect
Queries and parameters
routing | actual | queries | parameters | how to get |
---|---|---|---|---|
user/:id |
http://localhost/#user/111 | {} |
{ id: 'tom' } |
$tom |
search |
http://localhost/#search?word=ikki | { word: 'ikki' } |
{} |
?word |
Generator helpers
ikki has several built-in helpers to create generators.
1) Edo
The edo
is the generator based flow-controler. This method creates a new generator which can be passed to the components. If you need serial/branching interactions with user's input, this will be a perfect solution.
Syntax
listeners
: space-sparated listeners' name inString
generator
: routing information is passed via arguments:path
,query
,param
. See details on "HTML router" section. Withyield
you can push the data to the component.
Examples
This is a simple conversation-like example. yield
returns the value given by the triggered event. Of cause, you can use if
, while
, ...etc as you like.
License
MIT