Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member rstuart's Avatar
    Join Date
    Jan 2008
    Location
    Brisbane, Australia
    Posts
    140
    Vote Rating
    4
    rstuart is on a distinguished road

      0  

    Default Views in MVC are not reusable

    Views in MVC are not reusable


    With the current design, Views in MVC are not reusable in a tabbed User Interface. To demonstrate, please consider the following example:

    Imagine we have two models, User and Pet. A User can have many Pets. That is, Pet belongs to User. Now imagine we have a border layout. In the West region we display a list of Users. Double clicking a User opens a new Tab in the center region. In that tab the list view for Pets is displayed which uses a Grid to display a list of the owning user's pets.

    In a REST application, the url for User 1's pets would look something like '/users/1/pets'. Every time you double click a user to open the list of pets, the url for the store (found in '/app/store/Pets.js') would need to change to '/user/{id_of_user}/pets'. Currently I don't believe it is possible to do this with MVC. This is because MVC in Ext JS 4 gives the store a storeId which is just its name in lower case. IE, if I have a store '/app/store/Pets.js', in my controller I refer to it as just 'pets' in my stores array on the controller and likewise, in my view (/app/view/pet/List.js), all I have to do to configure the store is add the config store: 'pets'. What this means is that there is only ever a single instance of that store. Changing its URL will affect every view using that store. What this means is to achieve a tabbed user interface like I am describing, you have to create a new store instance directly on the view or not list the Store on the controller and instead instantiate it yourself. This negates much of the code portability and readability that this new MVC system is meant to give you.

    I'm not sure what the fix is (stores need to be de-coupled from controllers starting with the storeId that is generated for starters), but in its current state, MVC is not very useful to anything other then very basic applications.

  2. #2
    Sencha User
    Join Date
    Feb 2008
    Location
    @bryanzarzuela
    Posts
    55
    Vote Rating
    0
    bzarzuela is on a distinguished road

      0  

    Default


    I agree. I'm actually starting to violate the MVC pattern by defining an instance of a store directly in a view just to circumvent this same problem.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    37
    Vote Rating
    0
    cntx is on a distinguished road

      0  

    Default


    I think u are trying to approach this with the wrong attention.
    Because u dont know how many users u will get, u dont know the actual url to get the users pets.

    But what u know is HOW the model of the pets or user look like.
    So u have the following

    Store:
    Code:
    Ext.define('App.store.User', {
        extend: 'Ext.date.Store',
        model: 'App.model.User',
        proxy: {
            type: 'rest',
            url: '/user'
        }
    });
    Models:
    Code:
    // user
    Ext.define('App.model.User', {
        extend: 'Ext.data.Model',
        fields: ['id', 'name']
    });
    
    // pet
    Ext.define('App.model.Pet', {
        extend: 'Ext.data.Model',
        fields: ['name']
    });
    Now u can do the following:
    1. inline store
    In your main view (your menu) u click a user (which is loaded on start into the user store)
    Now u open a tab, create a inline store with the pet model and the correct url, and bind the store directly.

    2. nested data
    You define nested data for the user, so u load the pets with them

    So u need to change the user and pet model a bit.
    Code:
    // user
    Ext.define('App.model.User', {
        extend: 'Ext.data.Model',
        fields: ['id', 'name'],
    
        hasMany: {model: 'App.model.Pet', name: 'pets'}
    });
    
    // pet
    Ext.define('App.model.Pet', {
        extend: 'Ext.data.Model',
        fields: ['name'],
        belongsTo: 'App.model.User'
    });
    Now u can load the pets with your user.
    But i think in your consideration, the first way is the better one.

    Hope i could help.

    just a quick edit:
    The store definition of extjs is permanent. So if u create a store, and change the proxy, u will change all data of components that are linked to this store. Because of that, u need to define a new store for each users pets.
    Last edited by cntx; 10 May 2011 at 12:57 AM. Reason: quick note

  4. #4
    Ext JS Premium Member rstuart's Avatar
    Join Date
    Jan 2008
    Location
    Brisbane, Australia
    Posts
    140
    Vote Rating
    4
    rstuart is on a distinguished road

      0  

    Default


    Quote Originally Posted by cntx View Post
    1. inline store
    In your main view (your menu) u click a user (which is loaded on start into the user store)
    Now u open a tab, create a inline store with the pet model and the correct url, and bind the store directly.
    This violates MVC. The view is supposed to represent data. Preparation of that data is to be done using the model and controller.

    Quote Originally Posted by cntx View Post
    2. nested data
    You define nested data for the user, so u load the pets with them
    This doesn't scale. What happens when I get a large user base or our example is expanded beyond just pets to property, jobs etc.?

    The problem is with the storeId. The controller needs to create a new instance of a store for every instance of the view that is created. I'm not sure how this is achieved but as it is currently, it is next to impossible to write a useful application using proper MVC architecture.

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    37
    Vote Rating
    0
    cntx is on a distinguished road

      0  

    Default


    Quote Originally Posted by rstuart View Post
    This violates MVC. The view is supposed to represent data. Preparation of that data is to be done using the model and controller.
    No its doesnt.
    MVC = Model View Controller, there is nothing about the stores.
    So u have your models (user,pet) your view (container with tabs) and your controller -> no violation.

    If you create a store inline and bind it to a view, it exists as long as the view exists, so if u close your tab or whatever, the store is destroyed also. So i dont see any problem of this, cos im creating a MCV App also, and this scenario just works fine.

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

      0  

    Default


    correct - a store is only a container for models, just like the panel is a container for controls.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  7. #7
    Ext JS Premium Member rstuart's Avatar
    Join Date
    Jan 2008
    Location
    Brisbane, Australia
    Posts
    140
    Vote Rating
    4
    rstuart is on a distinguished road

      0  

    Default


    Quote Originally Posted by steffenk View Post
    correct - a store is only a container for models, just like the panel is a container for controls.
    So you would be happy to place a panel in a controller? No, of course not, because a panel is a container for UI controls, something that belongs in a view. The same is true of stores and models.

    There is a good reason why the controller has a views and a stores array, Ext developers know stores belong in the model portion of MVC. MVC is a well know architecture that unfortunately shares part of its name with Ext Models. They are not synonymous, Ext Models only form part of what is refereed to as the Model in MVC. The model in MVC also includes query logic which, in Ext, is configured in the proxy, and this is the problem.

    The limitations of the current MVC implementation means that to implement the example I gave, you have to configure an inline store and its proxy on the view. This is not something that should be done in the view. Take a look at the definitions for the parts of MVC here.

  8. #8
    Sencha User
    Join Date
    May 2009
    Posts
    129
    Vote Rating
    1
    DiscoBoy is on a distinguished road

      0  

    Default


    I also don't understand how the MVC should really work? It is described as advantage that you can define proxies inside models, because then you don't need to configure them for every store. It makes sense that you configure your views with a store which only contains models.
    But in cases where my proxy URL changes like in the given REST example above "users/<userid>/pets" I would need to overwrite the url in each store or ... how do I load the specific data?
    I really haven't understood the idea behind yet it seems...Thanks for puting me back on the right track!

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

      0  

    Default


    Quote Originally Posted by rstuart View Post
    So you would be happy to place a panel in a controller? No, of course not, because a panel is a container for UI controls, something that belongs in a view. The same is true of stores and models.
    Of course not in controller.

    You have to accept that MVC is just a simple model of coding structure. In real world you always find most of logic in models. As stores are only container for models, they could have factory methods. Or if you need dynamic variants, create libraries with factory methods that are static, shared for all models. The same is possible for UI containers, use
    factory methods in view libraries.
    It depends on your application if some methods are specific or general, that is the decider for placing it.
    I think there is no "One best way", every one has his own way to structure, but MVC leads you in the right direction.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

Similar Threads

  1. reusable code
    By Stephan123 in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 22 Sep 2009, 7:14 AM
  2. Reusable Store / JSONReader
    By ext_fan in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 10 May 2008, 8:03 AM
  3. Simple reusable object
    By jplouffe in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 7 May 2008, 2:44 AM
  4. My reusable component...
    By Rocco in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 18 Jan 2008, 8:16 AM

Thread Participants: 4

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar