Last active
August 29, 2015 14:04
-
-
Save rblalock/c0872b210aa22efe3293 to your computer and use it in GitHub Desktop.
Idea for an uber-simplistic view / data binding in Alloy
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
var TiBind = require("ti.bind"); | |
var data = [ | |
{ someTitle: "Hello World" } | |
]; | |
TiBind($, data); |
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
/** | |
* 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]; | |
} | |
} | |
} | |
}; |
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
<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