1. #1
    Sencha User harley.333's Avatar
    Join Date
    Mar 2007
    Posts
    286
    Vote Rating
    4
    harley.333 is on a distinguished road

      0  

    Default MVC - Are stores meant to be reusable?

    MVC - Are stores meant to be reusable?


    Using the Ext4 MVC framework, are store definitions meant to be reusable?

    For example, let's say I have an "AllUsers" grid and a "SearchUsers" grid. The appearance of the grids would be identical (same columns, etc). I would expect to be able to use the same Store definition (just pass different parameters to the server).

    Following the examples, my Views define their separate gridpanels.
    Code:
    { xtype: "gridpanel", store: "App.grid.Users" }
    My Controllers should now be able to call the grids' store.load() method using different parameters. But the grids reference the same store instance. Loading one grid will refresh the other. This makes sense to me, and I can see the benefits of this behavior.

    I would expect the following code to create a new instance of the store for each grid:
    Code:
    { xtype: "gridpanel", store: Ext.create("App.grid.Users", {storeId: Ext.id()}) }
    When using this code, I get an error stating that the reader.read method doesn't exist. So, what am I doing wrong? Is it possible to reuse store definitions using the Ext4 MVC framework?
    harley.333 - Harley Jones
    harley.333@gmail.com - Find me on Google Talk.

  2. #2
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    you can bind stores to a component in your view inside controller.
    See Feedviewer example where this is done.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  3. #3
    Sencha User harley.333's Avatar
    Join Date
    Mar 2007
    Posts
    286
    Vote Rating
    4
    harley.333 is on a distinguished road

      0  

    Default


    Thanks Steffan. I had thought about this approach (I didn't remember the bindStore method), but it didn't feel very MVC-ish. I don't think Controllers should have this much knowledge of the Views.

    As I kept digging into the exceptions, I kept being pulled into the store's Proxy. It wasn't being constructed properly, etc, etc.

    In the end, I moved my proxy definition out of the Store and into the Model. Now, the Models know how to bind themselves, and my stores simply point to a Model. This move simplified my Stores so much that it effectively eliminated the need to define Stores separately. Some stores might have specific sorts/filters, but sorts and filters fall under the realm of the View (in my opinion). So, stores also fall into the realm of the View.

    Code:
    { xtype: "gridpanel", ..., store: { model: "App.model.myModel" } }
    This has addressed my issue because Store instances are now longer implicitly shared across controls and Views. This has also helped simplify my approach to the MVC framework.
    harley.333 - Harley Jones
    harley.333@gmail.com - Find me on Google Talk.

  4. #4
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    imho the controller is the right place. Views should not contain app logic at all, just configuration.
    The controller is the heart, and controller knows all about Models, Stores Views etc.

    I myself configure stores with a simple string and bind the correct store in controller onLaunch or in any action.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

Similar Threads

  1. what does this mean for check the type name is really what you meant?
    By yanzhiying95599 in forum Community Discussion
    Replies: 2
    Last Post: 1 Mar 2011, 1:35 AM
  2. The FLEX property in HBOX what is meant by
    By ALGZ in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 29 Dec 2009, 8:03 AM
  3. reusable code
    By Stephan123 in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 22 Sep 2009, 7:14 AM
  4. My reusable component...
    By Rocco in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 18 Jan 2008, 8:16 AM
  5. Trying to understand what is meant by the term "view"
    By Troy Wolf in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 24 Aug 2007, 4:06 AM

Thread Participants: 1