[ALOY-1275] Override not working when child controller is opened
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Alloy 1.6.0 |
Fix Version/s | n/a |
Components | Runtime |
Labels | qe-4.0.1 |
Reporter | Eric Wieber |
Assignee | Feon Sua Xin Miao |
Created | 2015-05-26T22:05:49.000+0000 |
Updated | 2015-07-29T00:12:48.000+0000 |
Description
When trying to override a function in an Alloy project, the function is not overridden if the 'child' controller is opened vs the function being called from the unopened controller.
*Steps to reproduce issue*
1. Create an Alloy project using the below files
2. Run the project
3. Click 'Create Ewan'
4. Click on 'Ewan'
*Actual Results*
An alert appears with "Ewan"
*Expected Results*
An alert appears with "OVERRIDE!"
*Notes*
If line 2 of
index.js
is changed to:
Alloy.createController("ewan").sayName()
the function works as expected.
*Files*
index.js:
function makeEwan(){
Alloy.createController("ewan").getView().open();
}
$.index.open();
person.js:
var args = arguments[0] || {};
exports.sayName = function(){
args.name ? alert(args.name) : alert($.name.text);
$.win2.close();
};
ewan.js:
exports.baseController = 'person';
$.name.text = "Ewan";
exports.sayName = function() {
alert("OVERRIDE!");
$.win2.close();
};
index.xml:
<Alloy>
<Window class="container">
<Label id="label" onClick="makeEwan">Create Ewan</Label>
</Window>
</Alloy>
person.xml:
<Alloy>
<Window id="win2" class="container">
<Label id="name" onClick="exports.sayName">No Name</Label>
</Window>
</Alloy>
This seems like a limitation on the existing Alloy's inheritance model, specifically inheriting event handlers is not supported directly. It's still possible to archive what you are trying to do, albeit with some changes in code: