1. #1
    Sencha User aflx's Avatar
    Join Date
    Jun 2011
    Location
    Berlin, Germany
    Posts
    64
    Vote Rating
    0
    aflx is on a distinguished road

      0  

    Default Custom proxy with B1

    Custom proxy with B1


    Hi,

    I'm trying to implement my own proxy. But I have some problems now.
    Everytime my create function is called, everything works well (data gets saved). But the operations are saved too! This means, that the create operation is still there and every following record to create is saved to this operation and gets recreated during the next call. After a few cycles, I have several records in the create operation of the batch.

    My create function looks like this:

    Code:
    create: function(operation, callback, scope) {
        if (!this._dbInitialized) {
            this.initDataBase();
        }
    
        var me = this;
    
        var records = operation.getRecords(),
            length = records.length,
            record,
            i;
    
        operation.setStarted();
    
        for (i = 0; i < length; i++) {
            record = records[i];
            me.setRecord(record);
        }
    
        operation.setCompleted();
        operation.setSuccessful();
    
        if (typeof callback == 'function') {
            callback.call(scope || me, operation);
        }
    },
    So the problem is now, that the created records are still present in the create batch/operation.
    I found the following in the Ext.data.Store:

    Code:
    ...
    // These methods are now just template methods since updating the records etc is all taken care of
    // by the operation itself.
    onCreateRecords: function(records, operation, success) {},
    onUpdateRecords: function(records, operation, success) {},
    ...
    These functions are called in onProxyWrite().
    Do I have to override these functions and remove the records by hand? Or what else do I have to do?

    At the moment it is very hard to write a custom proxy for ST2. Do you think, you can write some docu for this?

    Thx,
    Alex

    UPDATE:

    Ok, I think the problem is in the sync() function, where getNewRecords() is called, which filters records by the phantom flag:

    Code:
    sync: function() {
        var me = this,
            operations = {},
            toCreate = me.getNewRecords(),
    ...
    I saw in the debugger, that the added records have still the phantom flag set to true.
    Do I have to set this to false by hand? Where? Directly after I saved the record (me.setRecord()) or where is the best location for this?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    898
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    In your for loop, try record.phantom = false.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User aflx's Avatar
    Join Date
    Jun 2011
    Location
    Berlin, Germany
    Posts
    64
    Vote Rating
    0
    aflx is on a distinguished road

      0  

    Default


    Thx! That is working.

    Are there any plans to make a tutorial for this? What are the requirements for building a custom proxy... What are the operations and their properties good for (records vs. resultSet...). How does a proxy/store work in detail.

    Maybe this is interesting for other too?

    Best regards

    Alex

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Hi aflx,

    I will try to write some documentation on how to implement your own custom proxies. For now could you maybe post your custom proxy in full? I could take a look at it and see what I would change and add comments as to why.

    Thanks

  5. #5
    Sencha User aflx's Avatar
    Join Date
    Jun 2011
    Location
    Berlin, Germany
    Posts
    64
    Vote Rating
    0
    aflx is on a distinguished road

      0  

    Default


    Hey Tommy!
    I saw, that there is already another SqliteProxy mentioned in the forum: https://github.com/tomalex0/SenchaTouch-v2-SqliteProxy

    Maybe it is a good idea to help the author? It would be a great example too

    Bye,
    Alex

  6. #6
    Sencha User
    Join Date
    Oct 2011
    Location
    Pakistan
    Posts
    229
    Vote Rating
    1
    umr.ashrf is on a distinguished road

      0  

    Default


    Your proxy looks great to me. When I was writing a Proxy I found no tutorial for it and what I did was grab the source code of already written proxies and modify them according to what I want.

  7. #7
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    @aflx

    Thanks for the heads up, i'm really trying to make sqlite proxy work with ST2 beta version , i have made some changes to make read and create work, i haven't pushed those changes to github, if you want i will do it. It's better to have some guidelines for developing custom proxy .

    One doubt i want to raise is regarding use of "id", i think "id" is created even if it is not mentioned as model field. What if, the table needs a field with name as id, what all we need to look into, to avoid any conflicts?
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  8. #8
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Hi guys, I haven't been able to work on a guide for this for the next release, but I promise I will try to write one soon.

  9. #9
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    North Carolina
    Posts
    308
    Vote Rating
    22
    worthlutz will become famous soon enough

      1  

    Default


    Quote Originally Posted by TommyMaintz View Post
    Hi guys, I haven't been able to work on a guide for this for the next release, but I promise I will try to write one soon.
    Any progress on a guide? I'm not sure where to start.

    Worth

  10. #10
    Sencha User
    Join Date
    Mar 2012
    Posts
    18
    Vote Rating
    0
    haddow777 is on a distinguished road

      0  

    Default


    I am also hoping to find some better documentation on building proxies. For instance, what is the interaction between Stores and Proxies and Readers/Writers. What is the Operation object like and how does a Proxy specifically interact with them.

    Thank you for any help you can provide.