"RC" の分岐が、現在されgrounddbキャッシング-2016バージョン "2.0.0-rc.4"、
私のようなものを考えていた: (それを気にSOに直接書き込まれ、テストされていません)
// Create the grounded collection
foo = new Ground.Collection('test');
// Make it observe a source (it's aware of createdAt/updatedAt and
// removedAt entities)
foo.observeSource(bar.find());
bar.find()
observe
当社ミドルウェアは同じことを行う必要がある機能でカーソルを返します。のはそれのためにcreateMiddleWare
ヘルパーを作成してみましょう:
function createMiddleWare(source, middleware) {
const cursor = (typeof (source||{}).observe === 'function') ? source : source.find();
return {
observe: function(observerHandle) {
const sourceObserverHandle = cursor.observe({
added: doc => {
middleware.added.call(observerHandle, doc);
},
updated: (doc, oldDoc) => {
middleware.updated.call(observerHandle, doc, oldDoc);
},
removed: doc => {
middleware.removed.call(observerHandle, doc);
},
});
// Return stop handle
return sourceObserverHandle;
}
};
}
は使用方法:
foo = new Ground.Collection('test');
foo.observeSource(createMiddleware(bar.find(), {
added: function(doc) {
// just pass it through
this.added(doc);
},
updated: function(doc, oldDoc) {
const fooDoc = foo.findOne(doc._id);
// Example of a simple conflict handler:
if (fooDoc && doc.updatedAt < fooDoc.updatedAt) {
// Seems like the foo doc is newer? lets update the server...
// (we'll just use the regular bar, since thats the meteor
// collection and foo is the grounded data
bar.update(doc._id, fooDoc);
} else {
// pass through
this.updated(doc, oldDoc);
}
},
removed: function(doc) {
// again just pass through for now
this.removed(doc);
}
}));
私はhttps://atmospherejs.com/ground/dbから過去1,2ヶ月に地上DBをインストールしました。このGround DB IIはありますか? –
また、Groud DB IIにはそのミドルウェアオブザーバが用意されていますか?それとも、私はそれをすべてフォークする必要がありますか? UIのすべてのチェックボックスは、チェックボックスの状態(trueまたはfalse)、変更を行ったユーザーのID、および変更の日付でオブジェクトにバインドされます。ですから、私はこのデータをドキュメントが更新される前のDBと比較し、更新をキャンセルしたり、実行させたりする必要があります。あなたは私がそのようなコードでどこを結ぶことができるかについてのヒントを教えてください。 –
ところで、私は図書館の著者から答えを得ることに感謝します。 :) –