1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    68
    Vote Rating
    0
    iamcam is on a distinguished road

      0  

    Lightbulb Thoughts on the Data Package v.s. Ajax.request, et al.

    Thoughts on the Data Package v.s. Ajax.request, et al.


    I've been working on the Sencha Touch end of a project with the API dev team in another country the last few months. As I developed this app, I decided to make as full use of the Data Package as possible - something I haven't really tried before because Ext.Ajax.request() was usually enough. After struggling with the API team and Sencha Touch for more than I care to admit, I have some observations that I think might be helpful to somebody. Keep in mind I say this out of love - I'm deeply invested in using Sencha Touch on current and future projects, so my success is somewhat dependent on its success. Sencha Touch is, in my opinion, THE leader in hybrid mobile app frameworks.

    Here I attempt to outline a few frustrations and commentary. I realize that I'm not developing with a perfect system, and in some cases that might be the problem.

    ** params, extraParams, jsonData - encoding request data isn't synonymous across methods
    In my opinion, this shouldn't even be a question - Ajax.request should take the same parameters as data proxies, and vice versa. One example I can specifically point to is the use of jsonData in Ext.Ajax.request to send an encoded JSON object in the raw post data, however that's not even an option in the Data Package, to my knowledge... I have yet to find a way (hint: it seems you can only send key:value pairs with extraParams, even when sending application/json headers). SO, you can send JSON objects only in Ext.Ajax.request, but you can't send extra params as JSON objects using a store or model. HOWEVER, if you're syncing a save back to the server, it WILL send a JSON object.

    ** headers: The strange prison guards
    This sort of makes sense, but doesn't at the same time - by changing the headers you change the payload. Here's one example: I can send a username and password to the API for some user profile update. By default, we're sending www-form-urlencoded data. Not a problem in many cases. It's like posting a form on any website I've ever worked on. In the case that your server is asking for application/json headers? Well, that's different because now the data is moved from the "Form Data" section of your debugger to "Request Payload". Try it. If I were to write PHP to interpret the two, the difference would be $_POST vs $HTTP_RAW_POST_DATA. Honestly, I didn't even know the latter existed until my Sencha Touch app wasn't working with my local mock api while the international team was writing the real API with .NET (don't even get me started). Remember, I fully acknowledge that I'm working with imperfect systems. We have other things with the API going on and that's why I had to use the application/json headers in the first place... the problem is that the server wants to see the normal www-form-urlencoded version of the post data. In this case it would be nice to mix-and match data to header type, though I'm sure there's a technical standard to sending the raw post data for one v.s. the urlencoded post data in the other. This is too long-winded. Moving on.


    ** Stores v.s. Models v.s. Proxies: I've got no good subtitle
    This has been somewhat confusing to come up to speed with. Proxies are the easiest things to figure out - they store connection parameters. fine. But the difference between a store and a model. I thought I knew until I started reading that both a store and model can load data, or that's how it appears. And both stores and models can have their own proxies. Maybe I've missed something or I'm not remembering articles I've read, but it seems there's maybe too much functional overlap between stores and models. When I look at other frameworks, models are good for describing the contents of the data (fields), validation rules, and special methods. Models are also useful for loading the data from a data source. So what's with Stores? Are they supposed to be some kind of super model that unites all the data from related models, convenience class, a controller, or what? Sometimes I get the impression model instances are only good for single entries ( this.myModel.load(123, { ... }). Either way ... I"m using stores just fine - but to me the lines separating the two don't always seem clear (should they be merged?). And while I'm on the topic, why do I load data into a store, change a parameter in one record, then call store.save() but all the parameters and all the records get sent back to the server, even if identical to what they originally received from the server (never mind that I can't figure out why record.store.save() sends two requests... probably something I'm doing wrong).


    ** Documentation & Tutorials: Almost there
    Overall, I think the docs can be very helpful. I think there's so much going on with Sencha Touch that although there are some great docs to get you started, you're sort of up a creek once you move beyond that. API docs can be helpful, but they're often missing the important "Oh by the way..." notes, or extra info that would help a novice, but an expert wouldn't care about (Why does Ext.Model API docs even imply you can attach listeners for DOM events like onClick? And no - I didn't actually think I could do that, but what listeners DOES it use?). The tutorials are pretty good starts for the most basic information, but I sometimes left wanting a little more in-depth and advanced content.


    ** The End: Just one more thing
    I think I've written maybe too much. I tried to keep explanations relatively short, but still try to give enough detail. I'm expecting some flaming and other users pointing out that I obviously don't know what I'm talking about because of X, Y, and Z. Of course! Otherwise I wouldn't have written half of this stuff. Just be nice about it, OK? I really do hope I'm doing the community a service by pointing out some of the areas that have really fouled me up as I learn this extensive framework. Chances are that I'm not the only one having these same problems. I know some of the problems probably exist because I implemented something wrong. Or the documentation didn't clearly explain something. Or maybe the Data Package really does need some re-tooling to work consistently with Ext.Ajax requests (they are close cousins, after all). Either way, thank you for your time reading this whole post. I truly appreciate it, and further discussion is appreciated even more - starting with you.

    Take care, everyone.
    Cameron

  2. #2
    Touch Premium Member
    Join Date
    Sep 2008
    Location
    Orange County, CA, USA
    Posts
    186
    Vote Rating
    0
    Jack9 is on a distinguished road

      0  

    Default


    Stores don't enforce any type of data structure. The reader decides what data format it will accept. Models, conversely, do enforce a data structure (regardless of format).

    I don't know why a model has a proxy as it seems REST is bolted on to models, just to confuse newbies and to clutter design.

  3. #3
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    68
    Vote Rating
    0
    iamcam is on a distinguished road

      0  

    Default


    Generally I would agree, but we do have a case where a store loads a three-level deep model association from one URL, but it's only the deepest model that actually sends any data back to the server. So in that case, we have to set a different proxy/url to call another API method for the update.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    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


    Quote Originally Posted by Jack9 View Post
    I don't know why a model has a proxy
    You can do a load call on a Model to load a single Model instance and load it into a FormPanel to then get a few goodies, validations for one.
    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.

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    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


    Cameron,

    Thank you for your opinions and this post will be shared internally as well.
    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.

  6. #6
    Touch Premium Member
    Join Date
    Sep 2009
    Posts
    27
    Vote Rating
    1
    arislaw is on a distinguished road

      0  

    Default great post!

    great post!


    great thread! the post and the answers helped me to understand some points. I agree about the confusion between stores and model, but after some time of developement I started to use model and stores in a different way and I understand now the role each one plays. But I agree that it was a little bit strange in the beginning.