Developer at Klick Health
Two things are isomorphic if they sharea set of properties that interest us
//a variable var thing = "Macbook"; thing = "iPhone"; console.log( things ); // "iPhone"
//a getter-setter var thing = m.prop( "MacBook" ); thing( "iPhone" ); console.log( thing() ); // "iPhone"
Makes Async similar to Sync
var things = m.request({method: "GET", url: "/things.json"}) //get a list of things .then(function(list) { return list.slice(0, 10) }); //then slice it .then(function(list) { return list.slice(0, 3) }); //then slice it some more
e.g. Compare to jQuery
var things = $(".things") //get a list of things .slice(0, 10); //then slice it .slice(0, 3); //then slice it some more
Just like HTML, but in Javascript
m("div", [ // <div> m("a", {href: "http://google.ca"}, "Google") // <a href="http://google.ca">Google</a> ]) // </div>
m("div", [ //<div> [1,2,3].map(function(num) { // <a href="/page/1">Page 1</a> return m("a", {href: "/page/" + num}, "Page " + num) // <a href="/page/2">Page 2</a> }) // <a href="/page/3">Page 3</a> ]) //</div>
Let the browser and the framework do the heavy lifting
// Vanilla Javascript m("ul.things", [ m("li", "iPhone"), m("li", "Macbook"), ])
# Coffescript m "ul.things", m "li", "iPhone" m "li", "Macbook"
var demo = {}; demo.controller = function() { this.things = m.request({method: "GET", url: "/things.json"}); };
var demo = {}; demo.controller = function() { this.things = m.request({method: "GET", url: "/things.json"}); }; demo.view = function(ctrl) { return m("ul", [ // <ul> ctrl.things().map(function(thing) { // <li>iPhone</li> return m("li", thing.name) // <li>MacBook</li> }) // <li>iPod</li> ]) // </ul> } m.module(document.body, demo) // initialize
var demo = {}; demo.controller = function() { this.things = m.request({method: "GET", url: "/things.json"}); }; demo.view = function(ctrl) { return m("ul", [ ctrl.things().map(function(thing) { return m("li", {onclick: function() { thing.name += "!" }}, thing.name) }) ]) } m.module(document.body, demo) // initialize