Permalink
Browse files

destroy previously stored tweets on page load

  • Loading branch information...
1 parent ca614f5 commit f1a83d5bcec5f5395d7edadfeacdcdb581a815b7 Kamil Tusznio committed Nov 3, 2011
Showing with 19 additions and 17 deletions.
  1. +6 −5 index.coffee
  2. +13 −12 index.js
View
@@ -4,17 +4,18 @@ class Tracer extends Batman.App
query: ''
class Tracer.Tweet extends Batman.Model
@persist Batman.LocalStorage
+ @destroyAll: -> @get('all')?.forEach (t) -> t.destroy()
class Tracer.AppController extends Batman.Controller
- index: -> @render false
+ index: ->
+ Tracer.Tweet.destroyAll()
+ @render false
submitSearch: =>
Tracer.set 'hasSearched', yes
- Tracer.Tweet.all?.forEach (t) -> t.destroy()
+ Tracer.Tweet.destroyAll()
$.ajax 'http://search.twitter.com/search.json?q=' + encodeURI(Tracer.query),
dataType: 'jsonp'
success: (data) ->
for obj in data.results
tweet = new Tracer.Tweet obj
- tweet.save (error, record) ->
- throw error if error
- false
+ tweet.save (error, record) -> throw error if error
Tracer.run()
View
@@ -24,6 +24,12 @@
Tweet.__super__.constructor.apply(this, arguments);
}
Tweet.persist(Batman.LocalStorage);
+ Tweet.destroyAll = function() {
+ var _ref;
+ return (_ref = this.get('all')) != null ? _ref.forEach(function(t) {
+ return t.destroy();
+ }) : void 0;
+ };
return Tweet;
})();
Tracer.AppController = (function() {
@@ -33,24 +39,20 @@
AppController.__super__.constructor.apply(this, arguments);
}
AppController.prototype.index = function() {
+ Tracer.Tweet.destroyAll();
return this.render(false);
};
AppController.prototype.submitSearch = function() {
- var _ref;
Tracer.set('hasSearched', true);
- if ((_ref = Tracer.Tweet.all) != null) {
- _ref.forEach(function(t) {
- return t.destroy();
- });
- }
- $.ajax('http://search.twitter.com/search.json?q=' + encodeURI(Tracer.query), {
+ Tracer.Tweet.destroyAll();
+ return $.ajax('http://search.twitter.com/search.json?q=' + encodeURI(Tracer.query), {
dataType: 'jsonp',
success: function(data) {
- var obj, tweet, _i, _len, _ref2, _results;
- _ref2 = data.results;
+ var obj, tweet, _i, _len, _ref, _results;
+ _ref = data.results;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- obj = _ref2[_i];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ obj = _ref[_i];
tweet = new Tracer.Tweet(obj);
_results.push(tweet.save(function(error, record) {
if (error) {
@@ -61,7 +63,6 @@
return _results;
}
});
- return false;
};
return AppController;
})();

0 comments on commit f1a83d5

Please sign in to comment.