Results 1 to 6 of 6

Thread: How do I configure a view to use a different ViewModel and ViewController?

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2007
    Location
    Sydney, Australia
    Posts
    237
    Answers
    3

    Default How do I configure a view to use a different ViewModel and ViewController?

    Outside of Architect it is very straightforward to configure a component class to use a ViewModel and ViewController from some other component class.

    Is there a way to achieve this in Architect?

    I have actually been thinking about doing this for some time and and have only now gotten around to trying it. I can set controller and viewModel.type, but the existing (generated) values remain and there does not appear to be a way to delete the ViewModel and ViewController that were created in conjunction with the component class. I am quite surprised that I cannot do this as I hit a bug yesterday whereby a component class actually did lose the connection to its corresponding ViewController and I had to resort to configuring it manually (in the absence of this it was going up the component hierarchy). Ironically, this is actually what I am attempting to do intentionally today.

    Hints, advice, comments welcome.

    Scott.

  2. #2
    Sencha User jjohnston's Avatar
    Join Date
    Sep 2010
    Posts
    567
    Answers
    30

    Default

    Binding the View-VM-VC triad together as an unbreakable unit was a conscious decision we made when designing Architect's support for the MVVM architecture in Ext5. We realize that you lose some of the flexibility you have when they're totally decoupled, but by adding that limitation and treating them as a unit Architect is able to gain knowledge and control around how your app is structured and provide a lot of helpful intelligence that we couldn't do otherwise.

    That said, I suppose you could create an override for your component class ("Create Override" button at the top of the code editor) that changes it to point to your other VM/VC. You'll lose all assistance from Architect in terms of view controller event handlers getting generated in the right place, resolving viewmodel data in the design view, etc. but it should work at runtime.
    Jason Johnston
    @lojjic
    Sencha Architect Development Team

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2007
    Location
    Sydney, Australia
    Posts
    237
    Answers
    3

    Default

    Quote Originally Posted by jjohnston View Post
    Binding the View-VM-VC triad together as an unbreakable unit was a conscious decision we made when designing Architect's support for the MVVM architecture in Ext5.
    This is a shame. I actually have some views that do not have a ViewController listed and these operate in the desired fashion (functionally, not in terms of placement of newly created handlers, etc.). My guess is that these views got into this state as part of the 4.2 to 5.0 conversion process.

    Still, I would have thought it would be easy enough to simply display the associated ViewModel and ViewController classes as configured on the View, as if they were the one "unbreakable unit". [As a developer I just hate it when people requesting features say "it should be easy to..."] In any case, if it is not supported the config panel should probably exert some level of control over them.

    As an alternative I end up having to fire an event and catch this in the desired controller - not too difficult, but not as all as clear as if I were able to bind to different ViewModel and ViewController classes as is catered for outside of Architect. But I will say the Events = no connection from place where event is fired to where event handler code is; Controller configuration = obvious connection to code that will execute.

    Thanks for your reply.

    Scott

  4. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Connecticut
    Posts
    1,003
    Answers
    12

    Default

    my 0.02 cents worth, since a LOT of code that was migrated from 4 to 5 came over naked (no VM and no VC), and since most of the UI on forms, etc, were in panels, I would create new empty component, and just drag the UI over to it. Only thing left to do was change any properties of the parent component (height, width, itemID, etc). Then I have a new component that is fully clothed.

  5. #5
    Sencha Premium Member
    Join Date
    Jul 2007
    Location
    Sydney, Australia
    Posts
    237
    Answers
    3

    Default

    Quote Originally Posted by blomasky View Post
    my 0.02 cents worth, since a LOT of code that was migrated from 4 to 5 came over naked (no VM and no VC), and since most of the UI on forms, etc, were in panels, I would create new empty component, and just drag the UI over to it. Only thing left to do was change any properties of the parent component (height, width, itemID, etc). Then I have a new component that is fully clothed.
    You describe how to repair a View that upon conversion does not have the, in this case desirable, associated ViewModel and ViewController classes.

    In my case I am after the opposite. I want be able to use different ViewModel and ViewController classes for a given view, either by specifying the classes or to obtaining them via the containment hierarchy.

    Thanks anyway for your reply. It provides a nice method of addressing the conversion inconsistency.

  6. #6
    Sencha Premium Member
    Join Date
    Jul 2007
    Location
    Sydney, Australia
    Posts
    237
    Answers
    3

    Default

    Just to round out my exploration of using different controllers with Architect I tried configuring a controller when instantiating an object thus:
    Code:
    myPanel.add({
        xtype: 'mysubpanel',
        controller: 'mypanel'
    });
    This does indeed allow my child view ('mysubpanel') to be instantiated with the controller of the parent view ('mypanel'). Functionally it works according to designed however once again, the existence of the controller and viewModel configurations are somewhat confusing and Architect can of course not provide any assistance with wiring things together (in fact it is necessary to define dummy methods in the generated controller for mysubpanel.

    As Architect's implementation of MVVM matures it would be nice (as I stated in an earlier post) to see the ability to specify the controller and viewModel types in the view and have these associated classes display exactly as if they were the generated ones. Can this be recorded somewhere as a feature request?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •