What are your best practices for backbone.js projects?

后端 未结 4 1135
盖世英雄少女心
盖世英雄少女心 2021-01-31 05:13

Although I\'m following backbone.js for some months and worked through a plethora of tutorials, I\'m still not confident enough in backbone (or my skills regarding it) to use it

相关标签:
4条回答
  • 2021-01-31 05:53

    There are a number of things that you can take care of while developing Backbone.js based applications. For example:

    1. Custom plugins and mixins
    2. Nested views/Sub views
    3. Partial view updating
    4. Template management - Storing, Pre-compiling at front end and back end
    5. Serializing models
    6. Relational data model
    7. Using Event dispatcher
    8. Subrouting
    9. Large scale application architecture etc.

    There are lot more concepts which are essential for developing single page Backbone.js based applications. You can try out my book Backbone.js Patterns and Best Practices which discusses all these points in detail.

    0 讨论(0)
  • 2021-01-31 05:57

    Since the answer for this question might be too long, because of the general scope it has, I'll leave these links here. I hope they will help some other people who find this question, as they helped me to have a better understanding of this framework and have a better application, with an efficient use of memory, a better organization of files and a more readable and maintainable code:

    http://ricostacruz.com/backbone-patterns/

    http://kilon.org/blog/2012/11/3-tips-for-writing-better-backbone-views/

    http://blog.involver.com/2012/01/26/testing-backbone-js-best-practices-2/

    http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/ (out of date solution but really important to read and understand!!)

    https://github.com/thomasdao/Backbone-View-Manager

    I wish I had this from the beginning.

    Cheers!

    0 讨论(0)
  • 2021-01-31 05:59

    Here is a list of questions you seem to have asked:

    backbone.js best practices/recipes
    My number one practice/recipe is to dive into the backbone.js code and read it, step through it with js debugger even. The code is well documented and is an excellent example of what modern JS code should be.

    How do you handle nested collections/views?
    Afaik there is no "simple way" to handle nested collections and handling events that happen in a sub-collection. You'd have to implement it. I haven't had to deal with a collection of collections yet though, so maybe you can avoid it by restructuring your "data model". A model that has a collection of models in itself satisfies most of the requirement of a nested model.

    As far as views go, you're basically in control how they get rendered. A view as provided by backbone is nothing but a mechanism to get changes in corresponded model to your render code. You implement the rendering. So if you want nested views, you can use template engine that supports partials(If i understand correctly what you mean by nested views).

    JSON serialisation
    Whats your question? The backbone doc says "it's highly recommended to include json2.js"

    More complex queries between models?
    Again, whats your question? Backbone provides you structure to do your own thing, you have to implement the complexities yourself

    Relations between models
    Again, you are implementing the models. Your models can contain other models. What you do with them and how you interact is up to you. In my experience its wasn't necessary to replicate the backend data model in javascript. Its quite possible that your front-end models will be simpler than the backend ones.

    Model inheritance
    By using backbone.js you are already using model inheritance. This is what happens when you write var MyModel = Backbone.Model.extend...

    Sorry for not going into more detail, but like Thomas Davis said, the questions were very vague. You'd get more detailed answer on a more detailed question describing a specific problem you're having.

    0 讨论(0)
  • 2021-01-31 06:12

    I think the questions are a bit vague to be answered in a simple post.

    I am nearing completion of a full web app done in Backbone.js and would also like to discuss these best practices so I can revise some choices quickly before launch.

    I am working on backbonetutorials.com at the moment to try group these harder questions together eventually.

    Solutions to saving collections will probably be the first question but would be awesome if there was some community engagement.

    0 讨论(0)
提交回复
热议问题