2
votes

I try to develop my own proxy (extends Ext.data.proxy.Proxy). after getting the response from my server (json) I can decode it and using my Json reader I create the set of records to commit to the store. As I understand I have to create an Operation object and commit the data with operation.commitRecords(). But this line if (clientRecords && clientRecords.length) never passes as clientRecords is undefined. I cannot understand how to use this object neither how to initialize it. This is my current code:

   options.action = options.action || 'read';
   var operation = new Ext.data.Operation(options);
   var json = reader.read(response);
   operation.commitRecords(json.records);

What should I do in order to commit the records? Thanks in advance!

2
This is interesting, I don't know the answer, but could you give some context? Why do you need a new proxy? Why don't you override Server.js? Also more code from your proxy would be nice. Not that I'm sure I can help, but just interested.. - Amit Aviv
I'm trying to do some implementation for websockets. I just want to know having only a set of records and a store, what can I do to update the store. - Lalao
Generally you can just use loadData when you have a set of records and a store, but that doesn't answer your initial question.. - Amit Aviv
Did you check ExtJS-WebSocket? - Amit Aviv
Yes I did but its not what I am looking for - Lalao

2 Answers

0
votes

That's not the proxy that is supposed to create the operation, it is the store. Then it passes this operation to the proxy, along with a callback. The proxy executes the operation in its own way and, when it is done, use the callback to notify the store.

So, the short answer to your question is that you need to execute the callback passed to the CRUD method you're implementing. Let's say it's read (Amit's right that some context about your code could have helped). So that would be something like:

// see, the operation is given to us
read: function(operation, callback, scope) {
    var me = this;
    doWebsocketMagic(function() {
        // notify the store
        Ext.callback(callback, scope || me, [operation]);
    });
}

Now, that won't be enough, because proxies are expected to manipulate the operation. You'll have to read the code from other proxies to know how. ServerProxy would have saved you that work, but you're not working with HTTP requests ("ServerProxy should ideally be named HttpProxy"). No luck.

So you should start by read the code of the read method of MemoryProxy. It offers, in one single place, an example of everything (I think) that you've got to do.

Then, maybe you can go clever about it:

Ext.define('My.WebsocketProxy', {
    extend: 'Ext.data.proxy.Memory'

    ,read: function(operation, callback, scope) {
        var me = this;
        doWebsocketMagic(function(response) {
            me.data = response;
            Ext.data.proxy.Memory.prototype.read.call(me, operation, callback, scope);
        });
    }
});
0
votes

Ok...Having searched how the store initializes the operation then it calls the proxies read method with callback function onProxyLoad(operation);. So adding store.onProxyLoad(operation); populates the store properly. Thanks for the replies guys...they helped solving my problem.