Files
meteor/packages/ui/forms.js
David Greenspan ccde6a051f prepare to port Spacebars to new render API
- remove code for @annotations
- rewrite component.lookup
- take old API out of package.js, move to "old" dir

totally breaks everything including "shark" demo
2013-07-14 11:11:24 -07:00

48 lines
1.1 KiB
JavaScript

var getterImpl =
function (foo) {
var fooDep = foo + "Dep";
var _foo = "_" + foo;
return function () {
this[fooDep].depend();
return this[_foo];
};
};
Component.include({
extendHooks: {
fields: function (dict) {
var proto = this.prototype;
var type = this;
for (var fieldName in dict)
proto[fieldName] = getterImpl(fieldName);
type.include({
constructed: function () {
for (var fieldName in dict) {
this["_" + fieldName] = dict[fieldName];
this[fieldName + "Dep"] = new Deps.Dependency;
}
}
});
}
},
set: function (fieldName, fieldValue) {
var _foo = "_" + fieldName;
var fooDep = fieldName + "Dep";
if ((_foo in this) && (fooDep in this)) {
// XXX compare with something besides `===`?
// do fields have to be EJSON or can they be anything?
if (fieldValue !== this[_foo]) {
this[_foo] = fieldValue;
if (fooDep in this)
this[fooDep].changed();
}
} else {
throw new Error("No such field: " + fieldName);
}
}
});