Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1275] Override not working when child controller is opened

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sAlloy 1.6.0
Fix Version/sn/a
ComponentsRuntime
Labelsqe-4.0.1
ReporterEric Wieber
AssigneeFeon Sua Xin Miao
Created2015-05-26T22:05:49.000+0000
Updated2015-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>

Comments

  1. Feon Sua Xin Miao 2015-07-28

    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:
       function makeEwan(e){
       	var ewan = Alloy.createController("ewan");
       	ewan.init();
       	ewan.getView().open();
       }
       $.index.open();
       
       var args = arguments[0] || {};
       
       exports.sayName = function(){
       	args.name ? alert(args.name) : alert($.name.text);
       	$.win2.close();
       };
       
       exports.init = function() {
       	$.name.addEventListener('click', $.sayName);
       };
       
       <Alloy>
       	<Window id="win2" class="container">
       		<Label id="name">No Name</Label>
       	</Window>
       </Alloy>
       

JSON Source