Slide 33
Slide 33 text
Wrapping Ti.UI.* components
Passing arguments
exports.setText = function (text) { $.myVew.text = text.toUpperCase(); }
_.each(['text', 'color'], function (pr) {
var cam = pr[0].toUpperCase() + pr.substring(1);
var get = exports['get' + cam] || ($['get' + cam] = function () { retur $.myVew[pr]; });
var set = exports['set' + cam] || ($['set' + cam] = function (val) { $.myVew[pr] = val; });
Object.defineProperty($, pr, {
get: get,
set: set
});
});
exports.applyProperties = function(properties) {
properties = _.omit(properties, 'id', '__parentSymbol', '__itemTemplate', '$model');
var apply = {};
_.each(properties, function (val, pr) {
! var fn = 'set' + pr[0].toUpperCase() + pr.substring(1);
! exports[fn] ? exports[fn](val) : (apply[pr] = val);
});
_.isEmpty(apply) || $.myVew.applyProperties(apply);
}
exports.applyProperties(arguments[0]);
• Looping _.keys($.myVew) would only give set properties
• Add set/get on $ as so applyProperties can't find them
• Define properties on $ as that's the final object
• Filter Alloy properties as (__parentSymbol would give memory leak)