timpone
timpone

Reputation: 19979

Migrating from jquery to Backbone - does it make sense with this?

Noob Backbone.js user here. I have a jquery app that I'd like to migrate to Backbone. I have read through docs and the relevant chapter in O'Reilly's Javascript Web Applications.

The jQuery part does the following:

  1. on document.ready, make an Ajax request to get back two (potentially) big pieces of Json. One piece of json represents all the comments and the other represents all the images. Both of these are keyed against the item-id and appropriate div's are created in the markup.

  2. each ajax call on success iterates through the results and appends them into the appropriate div

  3. After this is rendered out, the app listens on the more-info-$id's and toggles displaying them

A couple of ?'s

  1. Does this sound like a good candidate for a Backbone app?

  2. It seems like Backbone has a pretty specific set of uses. Would I want to create a set of Comments and Images and then make the appropriate ajax call? Could I essentially keep the same json and just instantiate a new Comment object and a new Image object and then add to the respective collections?

  3. It seems most of Backbone is around handling events - is using it in this document.ready way ill advised?

  4. Would something as simple as a toggle call be better left in jQuery?

Sorry for all the noob questions, just don't want to get down a wrong path.

thx

Upvotes: 2

Views: 560

Answers (1)

rfunduk
rfunduk

Reputation: 30452

Backbone isn't a replacement for jQuery, it still uses jQuery (or Zepto) out of the box to do ajax/DOM stuff anyway.

In your case Backbone seems like it could be a good candidate for organizing what you already have. What you've done above is describe what you app is currently doing, it would help to have more information along the lines of what your app should do from a conceptual angle - this way we can attempt to design a method of organization (appropriate models/collections/views, etc) for your use-case (this is what Backbone excels at, it definitely does not have a 'specific set of uses', don't worry :)).

Upvotes: 2

Related Questions