I am trying to develop refresh feature on social feed, Evry minute i am checking if there are some new tweets.
I am fetching a backbone collection (col1) and after 1 min i am fetching the same collection (col2) to compare and extract new tweets.
@tweets = App.request "tweets:entities"
that = @
setInterval (->
that.freshTweetsCol = App.request "tweets:entities"
App.execute "when:fetched", that.freshTweetsCol, =>
console.log(that.freshTweetsCol == that.tweets)
freshTweets = _(that.freshTweetsCol.models).without(that.tweets.models)
freshTweets2 = _.difference(that.freshTweetsCol.toJSON(),that.tweets.toJSON())
console.log(freshTweets)
console.log(freshTweets2)
return
), 10000
- @tweets gives me collection with 20 models
- that.freshTweetsCol gives me collection with the same 20 models as in @tweets, if there is no new tweets.
- console.log(that.freshTweetsCol == that.tweets) gives false, even if models are the same
- console.log(freshTweets) gives me array of 20 models, each called 'Tweet'
- console.log(freshTweets2) gives me array of 20 objects
how can i check only for new tweets? why I cannot use _.difference method to compare the collections?