4 ms·
function renderApplication(tweets) { return(document.dom.ul( { class: 'tweets' }, tweets .sort(compareTweetsByScore) .slice(0, 5) .m
by marknutter 12y ago
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);
})
));
}
What I like best about Ember and Angular.js is that you don't have any hint of the DOM in your controllers. I don't like how the above example mixes concerns.
- antris 12y agoIts concern is mapping the tweets (data) into a view (another form of data). That is one concern. If you like, you can split it into smaller functions (since everything is referentially transparent, unlike in MVC), but that would be overkill considering the given example.
- camus2 12y agothe point i think is scope injection makes controllers clueless about any view responsability. That's a powerfull idea. Well they are not totally clueless because one still needs to "force update the view" sometimes in Angular ($scope.$apply),but this can be avoided by using Angular promise api.
- benaiah 12y agoThis would be considered part of the view, not the controller, and would thus be organized as such. It's also a very small example - a real application would have a number of differences with this.
- danabramov 12y agoPete Hunt talks about this in Rethinking Best Practices video[1]. This is one concern, not two. [1]: http://www.youtube.com/watch?feature=player_embedded&v=x7cQ3mrcKaY http://www.youtube.com/watch?feature=player_embedded&v=x7cQ3...