This is a migrated thread and some comments may be shown as answers.

Datasource.transport.push How does it work?

0 Answers 114 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
TkNeo
Top achievements
Rank 1
TkNeo asked on 05 Oct 2015, 08:27 PM

I am not clear how exactly the grid-datasource (websocket) demo works. Specifically, i am confused about this code:

 

push: function(options) {
    //Listen to the "message" event fired when the server pushes data
    ws.addEventListener("message", function(e) {
        var result = JSON.parse(e.data);
 
        //Check what the push type is and invoke the corresponding callback.
        if (result.type == "push-update") {
            options.pushUpdate(result);
        } else if (result.type == "push-destroy") {
            options.pushDestroy(result);
        } else if (result.type == "push-create") {
            options.pushCreate(result);
        }
    });
},

The documentation says the "The function invoked during transport initialization which sets up push notifications. The data source will call this function only once and provide callbacks which will handle push notifications (data pushed from the server).". So, it seems like the purpose of this push is to set callbacks ? Isn't that what we are doing in the send function ? Before we send any data, we specify callbacks.

 

Secondly, what is this "options"  parameter. As per the documentation its a callback object. But then where are the options.purshCreate(), options.pushUpdate() etc defined ?  What are they doing ?

 

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
TkNeo
Top achievements
Rank 1
Share this question
or