Find out that I am creating Twitter as an application. So you know that Twitter sends a GET request to the server every N seconds to check for new tweets. If there are new tweets, he creates hidden li elements and shows a button with "N new Tweets". If you click on it, it will display the hidden li elements, showing new tweets. But the behavior is different when you add a new tweet: tweets are visible. You do not need to click a button to see it.
I have already done the first part, for hidden tweets. Regarding the publication of the new tweet and shown on it, I thought it would be easy to do this by creating a new model, calling collection.create () and firing the correct event, for example:
var newTweet = new Tweet();
newTweet.set( );
var created_tweet = this.collection.create( newTweet, { silent: true, wait: true } );
this.collection.trigger("posted_new_tweet", created_tweet);
Then my collection is subscribed to the event "published_new_tweet", so every time a user publishes a new tweet, a specific method of my collection is called. This approach worked fine until I got an error due to the created_comment variable passed in the trigger: it is not "complete". I mean, the model has attributes like "id" or * "created_on" *, which are undefined. These attributes are computed on the server side, but I thought that if I pass wait = true , it will wait and update my model with the response given by the server (when a POST request is made to the server, it returns the newly created model in json)
? ? , ?
!