http://developers.theguardian.com
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin urna odio, aliquam vulputate faucibus id, elementum lobortis felis. Mauris urna dolor, placerat ac sagittis quis.
(defn greet [name] (.concat "Hello " name))
(greet "Robert")
(defn currentSections
[allSections, activeSections]
(.filter list (fn [section]
(.some activeSections
(fn [activeSection]
(identical?
section.id activeSection.id))))))
var greet = exports.greet
= function greet(name) {
return 'Hello '.concat(name);
};
greet('Robert');
var currentSections
= exports.currentSections
= function currentSections(
allSections, activeSections) {
return list.filter(
function (section) {
return activeSections.some(
function (activeSection) {
return section.id
=== activeSection.id;
});
});
};
Compiled Clojurescript
Prefix notation
Includes quite a few Clojure standard library functions
Clojure data structures
Javascript
Prototype extension
Arrays-compatible interface
Feature comparable with Lo-Dash and Underscore
Influenced by Clojure data structures
var data = Immutable.fromJS({'person' :
{'name' :
{'first' : 'Robert', 'family' : 'Rees'}
}
, 'age' : 452});
var nameCursor = Cursor.from(data, ['person', 'name']);
nameCursor.update('first', function(name) {return name.toUpperCase();} );
data.getIn(['person', 'name', 'first']); // ROBERT
var immstruct = require('immstruct'),
React = require('react');
var appData = immstruct({greeting: "Hello", guest: {name: ""}});
function render() {
React.render(Component(appData.cursor()), documentElement);
}
render();
appData.on('next-animation-frame', render);
Blog: rrees.me
Twitter: rrees
http://slides.com/rrees/trojan-horsing-clojure-with-js