Created
November 5, 2011 02:50
-
-
Save kwhinnery/1341023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Wrapper class to create extensible Titanium components | |
exports.Component = function(/*Object*/ tiView) { | |
var self = { | |
__viewProxy:tiView | |
}; | |
//passthrough for add | |
self.add = function(/*Object*/ tiChildView) { | |
var v = tiChildView.__viewProxy||tiChildView; | |
self.__viewProxy.add(v); | |
}; | |
//passthrough for remove | |
self.remove = function(/*Object*/ tiChildView) { | |
var v = tiChildView.__viewProxy||tiChildView; | |
self.__viewProxy.remove(v); | |
}; | |
//passthrough for open | |
self.open = function(args) { | |
if (self.__viewProxy.open) { | |
self.__viewProxy.open(args||{animated:false}); | |
} | |
}; | |
//set/get properties on the view proxy | |
self.set = function(k,v) { | |
self.__viewProxy[k] = v; | |
}; | |
self.get = function(k) { | |
return self.__viewProxy[k]; | |
} | |
//passthrough for animation | |
self.animate = function(args,cb) { | |
self.__viewProxy.animate(args,cb||function(){}); | |
}; | |
//passthrough and shorthand for events | |
self.on = function(name,cb) { | |
self.__viewProxy.addEventListener(name,cb); | |
}; | |
self.fire = function(name,e) { | |
self.__viewProxy.fireEvent(name,e||{}); | |
} | |
//memory management | |
self.onDestroy = function(){}; | |
self.release = function() { | |
self.__viewProxy = null; | |
self.onDestroy(); | |
}; | |
return self; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOICE! I like it.