Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ability to augment uiActions in subclass #70

Merged
merged 7 commits into from
Nov 7, 2013
Merged

Implement ability to augment uiActions in subclass #70

merged 7 commits into from
Nov 7, 2013

Conversation

hieuhuynh
Copy link
Contributor

Hi Peter,

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

@petermichaux
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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

@petermichaux
Copy link
Owner

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
Copy link
Owner

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.

Modified test to check overwritten uiActions in subclass. Added new
test to check subclass of dynamically changed superclass uiActions.
@petermichaux
Copy link
Owner

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

@petermichaux
Copy link
Owner

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.

petermichaux added a commit that referenced this pull request Nov 7, 2013
Implement ability to augment uiActions in subclass
@petermichaux petermichaux merged commit e8ee292 into petermichaux:master Nov 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants