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

    Join Date
    Feb 2003
    Posts
    154
    Rep Power
    14

    Backbone.js & Websockets


    Hi,

    I'm trying to get my head around how the use of the web socket protocol will result in a view in a web app being kept in sync with records/documents in a collection/table.

    The basic architecture is:


    Backbone.js View (client) --> Backbone.js Model (client) --> REST service (server) --> Business Layer (server) --> DAO Layer (server) --> Database

    The idea is to create a model in Backbone.js from which Backbone generates the view & then to use websockets by overriding Backbone.sync method to enable real time updates from changes in the DB.

    What I'm fundamentally not understanding is that, after I have a webpage open on the client displaying a view of a Backbone model, if I make a change to add a record/document to the collection/table in the database, how does the architecture propagate that change in the DB back up the layers to the REST service & back (pushed) onto the client (Backbone model)?
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,298
    Rep Power
    7170
    You'd probably want use something akin to the observer pattern.

    When you create a model on the client-side, you would want to send some message over your open socket indicating that you want to listen for changes to that particular data. In either your business layer or your DAO layer, you would notify any observers whenever a data change is made. When your server-side code is notified of a data change, it can send some message back over the open socket to the client-side and the client-side can update its model.
    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