I've been working my way through:
http://blog.andyet.com/2011/02/15/re-using-backbonejs-models-on-the-server-with-node
I have a few questions about sharing models server-side and a few questions about overriding sync. Real-time model syncing architecture ftw.
Models
So in this example he syncs his whole application state. Part of my application state is the User model, this handles things like logging in, finding the type of platform they are using, etc. Am I using this wrong? I have client side session data in this model, something that really doesn't need to be on the server, should I put this on the server anyway?
For other models that are strictly application data that should be synced with the server, how do I manage these model on the server? Is there a "view" type component that handels changes to the model and acts on the model how the server needs to?
Sync
I want to override the sync method to sync with the server and any other clients that need the updated data. How could you write a sync method that works client -> server and server -> client so that no matter where it is called everyone get updated?
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Server-Side JavaScript vs Client-Side JavaScript So JavaScript can now be used not only on the client-side but also on the server.
BackboneJS is a lightweight JavaScript library that allows to develop and structure the client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.
Backbone. js is a JavaScript framework that helps you organize your code. It is literally a backbone upon which you build your application. It doesn't provide widgets (like jQuery UI or Dojo).
There are a a couple of aspects that make backbone a very good fit for client applications, but not not at all useful for server-based environments.
The core of backbone is its Events module, which the framework is built around (models are basically event-managed collections, views are glue code for rendering based on model event changes, etc...), is pretty much useless on a server: the only real event you're ever getting is the request, or the various events for socket data, and both are handled by (and are taken care of for) by the middleware and node itself.
Models:
if you're using some kind of ORM on your server, it should already provide the event handling necessary for dealing with model changes. And since you dont do any dynamic view updates on the server, you don't need any of the infrastructure backbone provides for models.
if you aren't using an ORM (as in realtime, never logged chat :), you can use Backbone's models, but they aren't suited for larger datasets or any kind of storage, and in the end you're still using an underscore-wrapped Hash / Array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With