start of real (cursor-based) Each

This commit is contained in:
David Greenspan
2013-07-09 19:06:49 -07:00
parent 7d1d8069d6
commit 16624569ec
5 changed files with 53 additions and 13 deletions

View File

@@ -104,13 +104,13 @@ Either = UIComponent.extend({
elseContent: Span
}),
{ type: Span });
buf(new _UI.Each({
/* buf(new _UI.Each({
content: UIComponent.extend({
render: function (buf) {
buf("<div>Each ", String(this.data()), "</div>");
}
})
}));
}));*/
}
});

View File

@@ -34,16 +34,6 @@ _UI.If = Component.extend({
}
});
_UI.Each = Component.extend({
typeName: 'Each',
render: function (buf) {
var self = this;
buf(self.content(function () { return 0; })),
buf(self.content(function () { return 1; }));
buf(self.content(function () { return 2; }));
}
});
_UI.Counter = Component.extend({
typeName: "Counter",
fields: {

49
packages/ui/each.js Normal file
View File

@@ -0,0 +1,49 @@
var Component = UIComponent;
_UI.Each = Component.extend({
typeName: 'Each',
render: function (buf) {
var self = this;
// XXX support arrays too.
// For now, we assume the data is a database cursor.
var cursor = self.data();
// XXX also support `null`
var self = this;
buf(self.content(function () { return 0; })),
buf(self.content(function () { return 1; }));
buf(self.content(function () { return 2; }));
}
});
// Function equal to LocalCollection._idStringify, or the identity
// function if we don't have LiveData. Converts item keys (i.e. DDP
// keys) to strings for storage in an OrderedDict.
var idStringify;
// XXX not clear if this is the right way to do a weak dependency
// now, post-linker
if (typeof LocalCollection !== 'undefined') {
idStringify = function (id) {
if (id === null)
return id;
else
return LocalCollection._idStringify(id);
};
} else {
idStringify = function (id) { return id; };
}
// XXX duplicated code from minimongo.js.
var applyChanges = function (doc, changeFields) {
_.each(changeFields, function (value, key) {
if (value === undefined)
delete doc[key];
else
doc[key] = value;
});
};

View File

@@ -182,7 +182,7 @@ Each = Component.extend({
var idStringify;
// XXX not clear if this is the right way to do a weak dependency
// now, on the linker branch
// now, post-linker
if (typeof LocalCollection !== 'undefined') {
idStringify = function (id) {
if (id === null)

View File

@@ -20,6 +20,7 @@ Package.on_use(function (api) {
'render.js',
'dom.js',
'forms.js',
'each.js',
'components.js',
'component.js', 'renderbuffer.js',