Skip to content

Instantly share code, notes, and snippets.

@rblalock
Last active August 29, 2015 14:04
Show Gist options
  • Save rblalock/c0872b210aa22efe3293 to your computer and use it in GitHub Desktop.
Save rblalock/c0872b210aa22efe3293 to your computer and use it in GitHub Desktop.
Idea for an uber-simplistic view / data binding in Alloy
var TiBind = require("ti.bind");
var data = [
{ someTitle: "Hello World" }
];
TiBind($, data);
/**
* Simple data binding for alloy
* @class ti.bind
* @param {Object} _controller Alloy Controller
* @param {Array} _data Object of properties to be bound to controller UI
* @param {Object} _transforms Takes an object of bindValues that take a transform string or (TODO) function
*/
module.exports = function(_controller, _data, _transforms) {
for(var view in _controller.__views) {
var uiview = _controller.__views[view];
if(uiview.bindKey) {
if(_transforms && _transforms[uiview.bindValue]) {
uiview[uiview.bindKey] = (typeof _transforms[uiview.bindValue] === "function") ? _transforms[uiview.bindValue]() : _transforms[uiview.bindValue];
} else {
uiview[uiview.bindKey] = _data[uiview.bindValue];
}
}
}
};
<Label bindKey="text" bindValue="someTitle" class="value" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment