mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Basic #each works
Needs {{else}} case. Also {{.}} doesn't work yet
This commit is contained in:
@@ -34,6 +34,8 @@ Blaze.renderList = function (funcSequence) {
|
||||
throw new Error("Expected a Blaze.Sequence of functions in " +
|
||||
"Blaze.renderList");
|
||||
|
||||
//XXX var controller = Blaze.currentController;
|
||||
|
||||
var initialMembers;
|
||||
var computation = Deps.autorun(function (c) {
|
||||
if (! c.firstRun)
|
||||
|
||||
@@ -10,7 +10,7 @@ var builtInBlockHelpers = SpacebarsCompiler._builtInBlockHelpers = {
|
||||
'if': 'Blaze.If',
|
||||
'unless': 'Blaze.Unless',
|
||||
'with': 'Spacebars.With2',
|
||||
'each': 'UI.Each'
|
||||
'each': 'Spacebars.Each'
|
||||
};
|
||||
|
||||
// These must be prefixed with `UI.` when you use them in a template.
|
||||
|
||||
@@ -16,5 +16,6 @@ Package.on_use(function (api) {
|
||||
|
||||
api.use('htmljs');
|
||||
api.use('ui');
|
||||
api.use('observe-sequence');
|
||||
api.add_files(['spacebars-runtime.js']);
|
||||
});
|
||||
|
||||
@@ -243,10 +243,41 @@ Spacebars.TemplateWith = function (argFunc, contentBlock) {
|
||||
};
|
||||
|
||||
Spacebars.With2 = function (argFunc, contentFunc, elseContentFunc) {
|
||||
var data = Blaze.Var(argFunc);
|
||||
var data = Blaze.Var(argFunc, UI.safeEquals);
|
||||
return Blaze.If(function () { return data.get(); },
|
||||
function () {
|
||||
return Blaze.With(data, contentFunc);
|
||||
},
|
||||
elseContentFunc);
|
||||
};
|
||||
|
||||
Spacebars.Each = function (argFunc, contentFunc, elseContentFunc) {
|
||||
var seq = new Blaze.Sequence;
|
||||
|
||||
var argVar = Blaze.Var(argFunc, UI.safeEquals);
|
||||
ObserveSequence.observe(function () {
|
||||
return argVar.get();
|
||||
}, {
|
||||
addedAt: function (id, item, index) {
|
||||
var dataVar = Blaze.Var(item, UI.safeEquals);
|
||||
var func = function () {
|
||||
return Blaze.With(dataVar, contentFunc);
|
||||
};
|
||||
func.dataVar = dataVar;
|
||||
seq.addItem(func, index);
|
||||
},
|
||||
removedAt: function (id, item, index) {
|
||||
seq.removeItem(index);
|
||||
},
|
||||
changedAt: function (id, newItem, oldItem, index) {
|
||||
seq.get(index).dataVar.set(newItem);
|
||||
},
|
||||
movedTo: function (id, item, fromIndex, toIndex) {
|
||||
var f = seq.get(fromIndex);
|
||||
seq.removeItem(fromIndex);
|
||||
seq.addItem(f, toIndex);
|
||||
}
|
||||
});
|
||||
|
||||
return Blaze.List(seq);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user