3 category: JavaScript libraries
12 Ractive is a UI library for JavaScript.
14 - <https://ractive.js.org/>
15 - <https://ractivejs.org/>
17 ### [Initialization](http://docs.ractivejs.org/latest/options)
22 template: '...', // required
25 init: function() {}, // on instantiate
26 complete: function() {}, // on finish animations
30 partials: { ... }, // global: Ractive.partials
31 transitions: { ... }, // global: Ractive.transitions
39 noIntro: true // true = disable transition on initial render
40 lazy: false // false = use keyevents, true = use change/blur
41 append: false // false = overwrite element, true = append
50 view.add('count', 1) //=> promise
51 view.subtract('count', 1) //=> promise
52 view.toggle('shown') //=> promise
56 view.reset({ a: true })
57 view.merge('list', [a,b,c])
62 ### Nodes and components
65 view.findAll('.klass')
67 view.nodes['hello'] // .find('#hello')
69 view.findComponent('photo')
70 view.findAllComponents('photo')
74 view.on('event', function() { ... })
83 view.insert('.node .path')
85 view.observe({ 'name': function() { ... } })
87 view.toHTML() //=> String
92 View = Ractive.extend({
97 ## [Components](https://github.com/RactiveJS/Ractive/wiki/Components)
99 See: https://github.com/RactiveJS/Ractive/issues/74
102 Widget = Ractive.extend({ ... })
104 ractive = new Ractive({
106 template: '<widget foo="bar"/>',
115 Ractive.partials.x = "<..>"
123 <button on-click='activate'>Activate!</button>
126 activate: function () { ... }
129 <button on-click='sort:name'>Sort by name</button>
130 view.on('sort', function (e, column) {
131 console.log('sorting by #{column}');
136 view.observe("name", function (name) {
137 console.log("Changed name to", name);
143 Body: {{{unescaped}}}
147 <li>{{this.name}}</li>
149 <li>{{.}}</li> <!-- same as 'this' -->
152 {{^user}}Not logged in{{/user}} <!-- if false -->
153 {{#user}}Welcome, sire{{/user}} <!-- if true -->
158 {{#statusDogs[selected]}}
160 ## Transformed attributes
162 This transforms the `list` attribute via a helper function called `sort()`.
164 {{# sort(list, "name") :num }}
165 <li>{{num}} - {{name}}</li>
166 {{/ end. any text goes here }}
169 sort: function(array, column) { return array.whatever(); }
176 <div intro="bump:{duration:400}">
178 Ractive.transitions.bump = function(t, params) {
179 params = t.processParams( params, {
181 color: t.isIntro ? 'rgb(0,255,0)' : 'rgb(255,0,0)'
193 ## [Decorators](http://docs.ractivejs.org/latest/decorators)
195 <span decorator="tooltip:hello there">Hover me</span>
198 tooltip: function (node, content) {
201 teardown: function () {
208 <span decorator="tooltip:'a','b',2,'c'">Hover me</span>
210 tooltip: function (node, a, b, two, c) { ... }
212 ## [Adaptors](http://docs.ractivejs.org/latest/adaptors)
215 filter: function (object, keypath, ractive) {
216 // return `true` if a particular object is of the type we want to adapt
218 wrap: function (ractive, object, keypath, prefixer) {
219 // set up event bindings here
220 object.on('change', function () { ractive.set(prefixer({...})); });
221 // then return a wrapper:
223 teardown: function () { .. },
224 // json representation
225 get: function () { return { a:2, b:3, c:4, ... }; },
226 // called on ractive.set
227 set: function (key, val) { },
228 // called on ractive.set on root (return false = die)
229 reset: function (data) { return false; }
234 ## [Computed properties](http://docs.ractivejs.org/latest/computed-properties)
237 template: '{{area}}',
239 area: function () { return this.get('width') * this.get('height'); }
240 area: '${width} * ${height}'
242 get: '${first} + " " + ${last}"
243 set: function (name) { ... }