View Full Version : [DUP] Config object for api property in Proxy, stores as string & not as object literal

23 Apr 2012, 7:45 AM
Sencha Architect 2.0.0 build 412

The api property on the Ajax Proxy serves to specify specific urls on CRUD action methods. Set through the property panel in Sencha Architect build 412, the object literal is interpreted and being incoporated in the generated code as a string. Which is invalid and leads Ext to ignore the api property & use the proxy url instead.

Introduce an object literal in Sencha Architect like

{ create: '/rest/usercreate.json',
read: '/rest/users.json'',
update : '/rest/userupdate.json',
destroy : '/rest/users.json'

Watch the underlying code and see how its being defined as the string:

'{ create: \'/rest/usercreate.json\',\n read: \'/rest/users.json\'\',\n update : \'/rest/userupdate.json\',\n destroy : \'/rest/users.json\'\n}'

Create, Update & Destroy actions are being ignored (the read is the default proxy url)
The fix is to manually edit the file, after which the API urls are being used correctly. This fix is not permanent as further editing of the Proxy will overwrite the customisation and restore the invalid string.

To correctly incorporate the API object literal as aforementioned literal and not a string literal

19 Feb 2013, 3:52 PM
Now I'm a little worried that it's still not fixed after all this time

20 Feb 2013, 7:02 PM
So Architect is attempting to protect you when you put in an invalid string. If you look at the above first post you'll notice that there is an extra stray ' at the end of read. This is why it was converted into a string.

Sencha Architect 2.2 will provide you additional feedback letting you know that it was unable to create an object. It will also allow you to put in random JS expressions of your own liking via a feature called processConfig for Ext JS or writing it in the initialize method of a Touch component.

20 Feb 2013, 8:51 PM
I guess it also doesn't like objects like the following:

create : Admin.wsurl('mapengine/create'),
read : Admin.wsurl('mapengine/read'),
update : Admin.wsurl('mapengine/update'),
destroy : Admin.wsurl('mapengine/delete')

I though I'd be able to get around the 'url' property having to be a string, but it sounds like processConfig will be what I'm after.

20 Feb 2013, 9:35 PM
Nope, there is no way it can resolve it and determine what it is (therefore it says oh lets convert it to a string).

processConfig will enable you to process that particular component and then do osmething like

processMyProxy: function(config) {
config.api = {
create : Admin.wsurl('mapengine/create'),
read : Admin.wsurl('mapengine/read'),
update : Admin.wsurl('mapengine/update'),
destroy : Admin.wsurl('mapengine/delete')
return config;

In the interim (Architect lower than 2.2) you can do this via an override of your store.

20 Feb 2013, 10:41 PM
Thanks for the explanation.

I like the idea of an override for the store, that suggestion sounds like the perfect way to update the url parameter in all of them in one location.

1 Mar 2013, 8:31 AM
I have exactly the same problem. I think Sencha is doing some implicit guess under the hood, such "protection" is really unnecessary and indeed annoying.

@aconran, my project got stuck because of this. Can you please give us a quick fix for this problem, or give us a workable preview of 2.2?


1 Mar 2013, 10:52 PM
Prior to 2.2, you will have to implement something like this via an override.

Architect will convert any object to a string which it cannot resolve.