93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
var Yatta, bindToChildren;
|
|
|
|
Yatta = require('./yatta');
|
|
|
|
bindToChildren = function(that) {
|
|
var attr, i, _i, _ref;
|
|
for (i = _i = 0, _ref = that.children.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
|
attr = that.children.item(i);
|
|
if (attr.name != null) {
|
|
attr.val = that.val.val(attr.name);
|
|
}
|
|
}
|
|
return that.val.observe(function(events) {
|
|
var event, newVal, _j, _len, _results;
|
|
_results = [];
|
|
for (_j = 0, _len = events.length; _j < _len; _j++) {
|
|
event = events[_j];
|
|
if (event.name != null) {
|
|
_results.push((function() {
|
|
var _k, _ref1, _results1;
|
|
_results1 = [];
|
|
for (i = _k = 0, _ref1 = that.children.length; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
|
|
attr = that.children.item(i);
|
|
if ((attr.name != null) && attr.name === event.name) {
|
|
newVal = that.val.val(attr.name);
|
|
if (attr.val !== newVal) {
|
|
_results1.push(attr.val = newVal);
|
|
} else {
|
|
_results1.push(void 0);
|
|
}
|
|
} else {
|
|
_results1.push(void 0);
|
|
}
|
|
}
|
|
return _results1;
|
|
})());
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
});
|
|
};
|
|
|
|
Polymer("yatta-element", {
|
|
ready: function() {
|
|
if (this.connector != null) {
|
|
this.val = new Yatta(this.connector);
|
|
return bindToChildren(this);
|
|
} else if (this.val != null) {
|
|
return bindToChildren(this);
|
|
}
|
|
},
|
|
valChanged: function() {
|
|
if ((this.val != null) && this.val.type === "Object") {
|
|
return bindToChildren(this);
|
|
}
|
|
},
|
|
connectorChanged: function() {
|
|
if (this.val == null) {
|
|
this.val = new Yatta(this.connector);
|
|
return bindToChildren(this);
|
|
}
|
|
}
|
|
});
|
|
|
|
Polymer("yatta-property", {
|
|
ready: function() {
|
|
if ((this.val != null) && (this.name != null)) {
|
|
if (this.val.constructor === Object) {
|
|
this.val = this.parentElement.val(this.name, this.val).val(this.name);
|
|
} else if (typeof this.val === "string") {
|
|
this.parentElement.val(this.name, this.val);
|
|
}
|
|
if (this.val.type === "Object") {
|
|
return bindToChildren(this);
|
|
}
|
|
}
|
|
},
|
|
valChanged: function() {
|
|
var _ref;
|
|
if ((this.val != null) && (this.name != null)) {
|
|
if (this.val.constructor === Object) {
|
|
return this.val = this.parentElement.val.val(this.name, this.val).val(this.name);
|
|
} else if (this.val.type === "Object") {
|
|
return bindToChildren(this);
|
|
} else if ((((_ref = this.parentElement.val) != null ? _ref.val : void 0) != null) && this.val !== this.parentElement.val.val(this.name)) {
|
|
return this.parentElement.val.val(this.name, this.val);
|
|
}
|
|
}
|
|
}
|
|
});
|