What is the difference between collection and model in Backbone.js? - backbone.js

I am really new in Backbone.js and I would like to know the main difference.
I'm wondering if is possible to use Backbone.js for local storage?
Thank you.

A collection is a list (collection) of models
Look at https://github.com/jeromegn/Backbone.localStorage

Related

Marionette model relationships

What's the best way to define relationships inside a Marionette/Backbone application?
I know there's Backbone-relational, but it hasn't been updated for over 6 months... Is there another way to create relationships in Backbone and/or Marionette?
Cheers!
As far as i can see the only libraries that look decent are backbone-associations and backbone-relational. In my opinion backbone associations is the best one since backbone relational hasn't been updated for a long time.

Backbone js app structure

Currently am writing all my business logic inside the view class which make my view class unmanageable. Am planning to create Backbone object and move all the business logic there and invoke it from view class. Please correct me with right way of thinking
Backbone in general does not provide an entity named Controller, this is one of the reasons which Backbone called MV*. Generally user interact with views, you know well this interact means change and update over models.
"So does Backbone.js have controllers? Not really. Backbone’s views typically contain
controller logic, and routers are used to help manage application state, but neither are
true controllers according to classical MVC." (Addy Osmani Book's)
so i think your way is not incorrect, but you can improve your project structure through this solutions:
Marrionette (and also Thorax ) is a excellent framework that provide such a excellent structure for your app. You can read this annotated code and get some tip from it.
You know certainly AMD a nice api to provide modular pattern in js. Require.js a nice tool for organize your code. For more information i recommend check TodoMVC + Backbone+Require code.

what pattern to use for notifcation of updates?

I am trying to design a angularcrud application where I can notify other users if an object has been updated. I have been reading a little bit about broadcasting and watchers. Just no idea where to place the code that handles all this? Should I implement a singleton messageservice that is injected in all my modules/controllers that handles this? Anyone experience with this?
I built a custom notification module. I made a module that has a directive and a singleton service like you said.
I'll share it with you:
https://github.com/breck421/angular-notifications/blob/master/NotificationModule.js
Let me know if you have any questions.
Thanks,
Jordan

backbone.js marionette and co

i am a beginner in the backbonejs world und bought a book from Addy Osmani’s Backbonejs Application. i am reading the book and i try to build an application with backbonejs. Somewhere in the book, he wrote a section about backbonejs extendsion and expose how to use marionettejs. I visited on Github backbonejs extendsion site, they have many extendsion included marionettejs. Now i am confused about using backbonejs, should i use extendsion like Marionettejs too or not? I know that extendsion can brings many advantages for webdevelopment, when i gonna use backbonejs then i should use marionettejs too? When it is useful to use extendsion when not?
I find Marionette to be a useful addition to Backbone, because it reduces the amount of repetitive code you need to write (unbinding event listeners when views close, rendering one view for each item in a collection and attaching it to the DOM, etc.).
There's a nice (short) comparison of Marionette and plain Backbone here: http://addyosmani.github.io/backbone-fundamentals/#boilerplate-rendering-code
Ultimately, the best tool for you will depend on what you want to achieve and what your preferences are.
Full disclosure: I may not be entirely objective, since I'm writing a book on Marionette. But I'm sure other members will provide you with their own opinions.

What is the best way to implement mvc using backbone?

I'm working on hybrid mobile application which has its base on backbone. I'm newbie to backbone. It is taking enormous time to learn the structuring itself. The logic is to present information from service to the user and post the information to the server. The information gathering spans across multiple pages. and the presentation of information also span across multiple page. What is the best structure to go with this? I'm really worried how model and collection can be used in my requirement. Any help is appreciated.
Honestly there is not enough information in your question to truly answer your problem.
But I can still give you some information.
Backbone is a MV* framework, it's two most important class being Model and View. The models works the usual way, and interact with the database. The views are far closer to the role of a Controller in usual MVC framworks, and take the information from the model to put it on the screen.
The information gathering spans across multiple pages. and the presentation of information also span across multiple page. What is the best structure to go with this?
Backbone works best with single page applications, so you should try to keep your whole application on a single page (that doesn't mean the end router sees a single page, as the java script can re-render the page when needed).
You can share the information among views like that:
var model = Model();
var view1 = view1({model:model});
var view2 = view2({model:model});
All the views will be able to access to the same model with the same data.
Further reading:
beginner:Backbone Tutorials
intermediate to expert : Osmani's awesome book

Resources