#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    154
    Rep Power
    14

    Backbone.js - getting model to detect when changes have occurred to the DB state


    I'm just getting started learning about how Backbone.js may be beneficial.

    I've got my head around the basic MVC principles as implemented by Backbone.js.

    What's confusing me, is that what I want to achieve is a way by which the Backbone.js model can detect changes to the state of its associated entity in the DB and then update its model accordingly and, thus any view listening on that model.

    Appreciate your thoughts on how this can be realised using backbone.js, given this seems like a fairly fundamental and common requirement?

    I should clarify that I don't wish for the JS library to talk directly to the DB, but via RESTFul interfaces which in turn talk through the typical n-tiers of service, business & persistence tiers.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    A system like that is actually quite a bit beyond the scope of libraries like backbone.js, not because it's not useful, but because it's complicated and requires specific server-side code and data structures to support it.

    On the client-side, the most universal way of doing this is to use a polling loop to execute an HTTP request every X seconds and see whether there are any changes on the server-side.

    On the server-side, you have to track the changes to the database in some way. There are a lot of ways to do this, but in a nutshell whatever method you choose needs to be able to efficiently determine when and what changes were made to the database.

    In your polling loop, the server checks for any changes and returns those back to the client-side for processing (like updating your backbone models).

    This sort of system tends to be fairly costly from a performance perspective.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo