Closed hieuhuynh closed 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.
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.
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.
Ok I've added the moreUIActions
property. This will allow inheriting the uiActions
and moreUIActions
. This will maintain backwards compatibility.
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;
},
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.
It looks to me like this code is good and ready to pull. How about documentation for maria.ElementView
and maria.ElementView.subclass
?
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.
Hi Peter,
I've added a check in
EventView.subclass
to see if uiActions object was defined and augment it in the subclass.