-
5 Feb 2012 9:24 AM #1
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:
So the problem is now, that the created records are still present in the create batch/operation.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); } },
I found the following in the Ext.data.Store:
These functions are called in onProxyWrite().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) {}, ...
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:
I saw in the debugger, that the added records have still the phantom flag set to true.Code:sync: function() { var me = this, operations = {}, toCreate = me.getNewRecords(), ...
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?
-
5 Feb 2012 11:20 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 436
In your for loop, try record.phantom = false.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Feb 2012 11:12 PM #3
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
-
5 Feb 2012 11:48 PM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
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
-
8 Feb 2012 10:29 AM #5
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
-
8 Feb 2012 10:57 AM #6
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.
-
12 Feb 2012 11:29 PM #7
@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?
-
13 Feb 2012 11:42 PM #8Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
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.
-
27 Jun 2012 5:54 AM #9
-
8 Aug 2012 12:55 PM #10
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.


Reply With Quote

