petermichaux / maria

The MVC framework for JavaScript applications. The real MVC. The Smalltalk MVC. The Gang of Four MVC.
BSD 2-Clause "Simplified" License
765 stars 51 forks source link

Implement ability to augment uiActions in subclass #70

Closed hieuhuynh closed 11 years ago

hieuhuynh commented 11 years ago

Hi Peter,

I've added a check in EventView.subclass to see if uiActions object was defined and augment it in the subclass.

petermichaux commented 11 years ago

I don't know how this would be used by the application developer. Updating the documentation and the automated tests as part of the pull request would give me a much better understanding of the intended use. Thanks.

hieuhuynh commented 11 years ago

This will allow the developer to do this:

maria.ElementView.subclass(myApp, 'baseView', {
    uiActions: {
        'click .foo': 'onClickFoo'
    }
});

myAppBaseView.subclass(myApp, 'subView', {
    uiActions: {
        'click .bar': 'onClickBar'
    }
});

subView will be able to delegate click .foo to the superclass and gives the ability to overwrite the handler method if the developer choose to.

petermichaux commented 11 years ago

That breaks backwards compatibility. uiActions does not currently inherit automatically and so it cannot start automatically inheriting. That is why I've suggested a moreUIActions property that does inherit.

hieuhuynh commented 11 years ago

Ok I've added the moreUIActions property. This will allow inheriting the uiActions and moreUIActions. This will maintain backwards compatibility.

petermichaux commented 11 years ago

This pull request determines the superclass UI actions at the time the subclass is defined. This is "early binding". Everything (or almost everything) in Maria uses "late binding" for the most dynamic and flexible possible behaviour. The UI actions of the super class may change during the life of the application and what is inherited by the subclass should change dynamically with it.

If you look in #64 you can see the code that we want to generate when the moreUIActions configuration parameter is used. Notice that the super class UI actions are determined at the last possible moment just before the more UI actions are appended and this happens every time getUIActions is called on the sub class.

getUIActions: function() {
    var uiActions = myApp.subView.superConstructor.prototype.getUIActions.call(this);
    uiActions['click .bar'] = 'onClickBar'
    return uiActions;
},
petermichaux commented 11 years ago

This looks very good to me.

Please add a superclass and a subclass UI action that have the same key but different values. Then check that the subclass value is the one that is ultimately used by the subclass. I think this will require exactly 3 lines to be added to the change set.

petermichaux commented 11 years ago

It looks to me like this code is good and ready to pull. How about documentation for maria.ElementView and maria.ElementView.subclass?

petermichaux commented 11 years ago

I don't know why I mentioned documentation for maria.ElementView. This pull request is only related to maria.ElementView.subclass sugar.

This is is a great addition to Maria. The code is compact, has tests, and documentation. Thank you, Hieu.