Murilo Pereira
May 2, 2014
function tweetScore(tweet) {
return(tweet.favorites_count + tweet.retweets_count);
}
function compareTweetsByScore(a, b) {
return(tweetScore(b) - tweetScore(a));
}
function renderApplication(tweets) {
return(document.dom.ul(
{ class: 'tweets' },
tweets
.sort(compareTweetsByScore)
.slice(0, 5)
.map(function(tweet) {
return(document.dom.li({ class: 'tweet' }, tweet.text);
})
));
}
var tweets = fetchTweets({ username: 'mpereira' }, { limit: 20 });
document.dom.render(renderApplication(tweets), document.body);
Backbone, Ember, Meteor, et al.
Not to be mistaken for "easy"
Easiness = Familiarity (subjective)
Simplicity = "Does/is one thing" (objective)
Also susceptible to the problems of data binding.
Rich Hickey
function tweetScore(tweet) {
return(tweet.favorites_count + tweet.retweets_count);
}
function compareTweetsByScore(a, b) {
return(tweetScore(b) - tweetScore(a));
}
function renderApplication(tweets) {
return(document.dom.ul(
{ class: 'tweets' },
tweets
.sort(compareTweetsByScore)
.slice(0, 5)
.map(function(tweet) {
return(document.dom.li({ class: 'tweet' }, tweet.text);
})
));
}
var tweets = fetchTweets({ username: 'mpereira' }, { limit: 20 });
document.dom.render(renderApplication(tweets), document.body);
function tweetScore(tweet) {
return(tweet.favorites_count + tweet.retweets_count);
}
function compareTweetsByScore(a, b) {
return(tweetScore(b) - tweetScore(a));
}
function renderApplication(tweets) {
return(React.DOM.ul(
{ className: 'tweets' },
tweets
.sort(compareTweetsByScore)
.slice(0, 5)
.map(function(tweet) {
return(React.DOM.li({ className: 'tweet' }, tweet.text);
})
));
}
var tweets = fetchTweets({ username: 'mpereira' }, { limit: 20 });
React.renderComponent(renderApplication(tweets), document.body);
Idempotent functions that describe your UI at any point in time.
*user input changes data from data_1 to data_2*
Pete Hunt
var Profile = React.createClass({
render: function() {
return(React.DOM.div(null, [
React.DOM.img(null, this.props.user.image),
React.DOM.p(null, this.props.user.name)
]);
}
});
var Tweets = React.createClass({
render: function() {
return(React.DOM.ul(null, this.props.tweets.map(function(tweet) {
return(React.DOM.li(null, tweet.text));
});
}
});
var TopTweets = React.createClass({
render: function() {
return(React.DOM.div(null, [
React.DOM.h1(null, 'Top Tweets'),
Profile({ user: this.props.user }),
Tweets({ tweets: this.props.user.tweets })
]);
}
});
React.renderComponent(TopTweets({ user: user }), document.body);
var Profile = React.createClass({
render: function() {
return(
<div>
<img href={this.props.user.image} />
<p>{this.props.user.name}</p>
</div>
);
}
});
var Tweets = React.createClass({
render: function() {
return(
<ul>
{this.props.tweets.map(function(tweet) {
return(<li>tweet.text</li>);
})};
</ul>
);
}
});
var TopTweets = React.createClass({
render: function() {
return(
<div>
<h1>Top Tweets</h1>
<Profile user={this.props.user} />
<Tweets tweets={this.props.user.tweets} />
</div>
);
}
});
React.renderComponent(TopTweets({ user: user }), document.body);
JavaScript sucks
We need JavaScript
Popular ones
(go (try
(let [tweets (<? (get-tweets-for "swannodette"))
first-url (<? (expand-url (first (parse-urls tweets))))
response (<? (http-get first-url))]
(. js/console (log "Most recent link text:" response)))
(catch js/Error e
(. js/console (error "Error with the twitterverse:" e)))))
To programmers, who will be able to build better programs, with less bugs, faster.
To the people and companies who will benefit from those programs.
(but you probably have, already)
David Nolen
30-40X faster than JS MVCs nothing to do with ClojureScript. Ditch stateful objects, ditch events. Be declarative. Immutability. That's it.
— David Nolen (@swannodette) December 15, 2013
And yet
Pete Hunt
Why?
How
Why?
How