Guest User

Untitled

a guest
Jun 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. var Twitter = Backbone.Controller.extend({
  2. REFRESH_INTERVAL: 10000,
  3. el: $('#left'),
  4. routes: {
  5. "twitter": "twitter",
  6. },
  7.  
  8. initialize: function() {
  9. _.bindAll(this, 'addOne', 'addAll', 'fetchLatest');
  10. Tweets.bind('refresh', this.addAll);
  11. Tweets.bind('add', this.addOne);
  12. Tweets.fetch();
  13. this.fetchLatest();
  14. },
  15.  
  16. addOne: function(tweet) {
  17. //console.log('add one');
  18. var view = new TweetView({model: tweet, 'id': tweet.attributes._id, 'className': 'tweet'});
  19. //console.log(view);
  20. $('#posts').prepend(view.render().el);
  21. },
  22.  
  23. addAll: function() {
  24. console.log('add all');
  25. Tweets.each(function(tweet) {
  26. var view = new TweetView({model: tweet, 'id': tweet.attributes._id, 'className': 'tweet'});
  27. $('#posts').append(view.render().el);
  28. });
  29. },
  30.  
  31. fetchLatest: function() {
  32. setInterval(function() {
  33. Tweets.fetchLatest();
  34. }, this.REFRESH_INTERVAL);
  35. }
  36.  
  37. });
Add Comment
Please, Sign In to add comment