Weaving Mithril into beautiful components
Weaving the safe, lightning speed and robust brillance of Mithril with the syntax sugar and integration freedom of Riot to help you journey beyond the mordor shadows of current web realities to the component hopes of the future.
Area | Byrnie | Mithril | Riot | React | Polymer | Vue | Angular |
---|---|---|---|---|---|---|---|
Weight minified | 16k*1 | 16k | 5k | 127k | 120k | 18k | 49k |
Virtual DOM | Yes | Yes | Yes | Yes | No | No | No |
Compatibility | IE6+2 | IE6+2 | IE8+2 | IE8+ | IE10+ | IE9+ | IE83, IE94, IE11+5 |
Binding | choice | choice | choice | one-way | two-way | two-way | two-way |
Load Speed | 0.28ms1 | 0.28ms | n/a6 | 25ms | n/a6 | n/a6 | 7.5ms |
TodoMVC | 127ms1 | 127ms | 594ms | 820ms | n/a6 | 259ms | 1,742ms |
Template Safety | Yes1 | Yes | n/a7 | n/a | n/a | n/a | No |
Notes:
- Assumed the same as Mithril at this stage of development
- With approperate shim
- Angular 1.2.x supports IE8 without IE8 issue support
- Angular 1.3.x supports IE9+
- Angular 2.x will support modern browsers that auto update (IE11+)
- Un-available. TodoMVC Pref needed
- Dependent upon at least the
Include Byrnie
<script src="byrnie.min.js"></script>
Include byrnie template
<script src="byrnie.min.js" type="text/x-byrnie"></script>
Basic template
<todo>
<div>
<input onchange={m.withAttr("value", app.vm.description)} value={app.vm.description()}/>
<button onclick={app.vm.add}>Add</button>
</div>
</todo>
Gets transpiled to MSX:
todo.view = function() {
return <div>
<input onchange={m.withAttr("value", app.vm.description)} value={app.vm.description()}/>
<button onclick={app.vm.add}>Add</button>
</div>
};
Then compiled to Mitril:
todo.view = function() {
return m("div", [
m("input"),
m("button", "Add")
]);
};
<todo>
<template> // optional, but improves clarity. Maps to Mithril view
<span>I'm <b>my-element</b>. This is my Shadow DOM.</span>
<core-ajax url="http://example.com/json" auto response="{{resp}}"></core-ajax>
<textarea value="{{resp}}"></textarea>
</template> // optional, but improves clarity
<script> // optional, but improves clarity. Maps to Mithril View-Model
vm.list = new todo.TodoList();
//a slot to store the name of a new todo before it is created
vm.description = m.prop("");
//adds a todo to the list, and clears the description field for user convenience
vm.add = function(description) {
if (description()) {
vm.list.push(new todo.Todo({description: description()}));
vm.description("");
}
};
}
</script> // optional, improves clarity
</todo>
Script gets wrapped in standard View-Model
todo.vm = (function() {
var vm = {}
vm.init = function() {
// script code here
}
return vm
}())
<script data-ns="myhome" src="byrnie.min.js"></script>
Var B = {}
Byrnie.scope('todo', B)
### One time render
```js
Byrnie.render(document, todo) // same as m.render(document, todo.view())
Byrnie.render('element-id', todo) // same as m.render(document.getElementById('element-id', todo.view()))
Byrnie.module(document, {controller: todo.controller, view: todo.view}) // same as m.module(document, {controller: todo.controller, view: todo.view})Â
Byrnie.module(document, todo) // todo must have .controller and .viewÂ
<todo>
<style>
.button { border: 1px }
</style>
<button class="button" onclick={app.vm.add}>Add</button>
</todo>
Gets emulated as Shadow DOM and gets transpiled to MSX until a living standard:
todo.view = function() {
return <div>
<style scoped> <!-- W3 compilance -->
.todo-button { border: 1px }
</style>
<input onchange={m.withAttr("value", app.vm.description)} value={app.vm.description()}/>
<button class="todo-button" onclick={app.vm.add}>Add</button>
</div>
};
Etc
- Rework Riot compiler to generate Mithril
- Sweet.js -> MSX -> Mithril
Add an issue to let me know if you support this idea or have other thoughts :-)
Pronounced: [bur-nee], a byrnie is a scottish variant for coat of mail armour or hauberk
Licensing labeled for reuse with modification
by Google images on 2015-01-29