[ALOY-600] Ability for baseController to handle events marked up in descendant views.
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2013-08-05T19:32:39.000+0000 |
Affected Version/s | Alloy 1.0.0 |
Fix Version/s | 2013 Sprint 16 |
Components | Runtime |
Labels | alloy |
Reporter | Pedro Enrique |
Assignee | Tony Lukasavage |
Created | 2013-03-19T21:15:30.000+0000 |
Updated | 2013-08-07T18:37:22.000+0000 |
Description
This error happens upon loading a controller when the view references an event handler that is only present in the baseController.
[ERROR] : Invalid type passed to function. expected: KrollCallback, was: NSNull in -[TiProxy addEventListener:] (TiProxy.m:797)
Discussion:
http://developer.appcelerator.com/question/149760/how-to-use-common-event-handlers-in-basecontroller-inherited-controller#comment-163640
Example project:
https://github.com/jbeuckm/AlloyBaseControllerEventHandler
Alloy's current inheritance is fairly limited, and there's a few things in the sample code that are not supported: * Inheritance involving any UI in the derived class * Inheritance involving markup events (a subset of the first point) That said, deferring event handlers to an derived class can still be achieved with a bit of a deeper understanding of he inheritance possibilities that Alloy does in fact provide. Below is a test case that should show you how to do so, which comments interspersed to make clear why things are done a certain way. I'm putting it in a gist as it includes a number of files and it would be messy to include it all here: https://gist.github.com/tonylukasavage/6158759 Running that example will allow Alloy to make use of an inherited event handler, albeit in a slightly more complex manner.