2016-11-08 62 views
3

[编辑]更新到地面DB V2,由代码更易读流星阵营:GroundDB突然空

我想在我的项目中使用GroundDB,所以我的流星反应的科尔多瓦应用程序也可以离线运行。在主容器中,我有以下代码:

let fullyLoaded = new ReactiveVar(false); 
let subscribed = false; 
let subscribedOnce = false; 
let checking = false; 

export default createContainer(() => { 

    if(Meteor.status().connected && !subscribedOnce && !subscribed){ 
     subscribed = true; 
     console.log("subscribing"); 
     Meteor.subscribe("localization", 
      ()=> { 
       localizationGrounded.keep(Localization.findNonGrounded()); 
       console.log("everything has been loaded once."); 
       console.log("Localization count after subscription: " + Localization.find().fetch().length); 

       fullyLoaded.set(true); 
       subscribed = false; 
       subscribedOnce = true; 
      } 

     ); 
    } 
    if(fullyLoaded.get()){ 
     console.log("Localization Count: " + Localization.find().fetch().length) 
    } 
    return { 
     isLoggedIn: !!Meteor.userId(), 
     isLoading: !fullyLoaded.get() || subscribed, 

    }; 
}, Main); 

此代码应该订阅“本地化”,如果它尚未加载已经。本地化收集的实现如下,查找()和findOne()方法已被覆盖调用find()方法用于接地DB:

export const Localization = new Mongo.Collection('localization'); 

if(Meteor.isClient){ 
    export let localizationGrounded = new Ground.Collection('localization', { 
     cleanupLocalData: false 
    }); 


    //rename find() to findNonGrounded 
    Localization.findNonGrounded = Localization.find; 

    localizationGrounded.observeSource(Localization.findNonGrounded()); 

    Localization.find = function(...args){ 
     console.log("finding from ground db"); 
     return localizationGrounded.find(...args); 
    }; 

    Localization.findOne = function(...args){ 
     console.log("finding one from ground db"); 
     return localizationGrounded.findOne(...args); 
    } 
} 

然而,这将产生以下输出:

subscribing 
everything has been loaded once 
finding from ground db 
Localization count after subscription: 28 
finding from ground db 
Localization count: 28 

看起来很好,对吧?不幸的是,createContainer()函数在此之后立即被调用,导致

... 
Localization count: 28 
//Lots of "finding one from ground db" indicating the page is being localized correctly 
finding from ground db 
Localization Count: 0 
//more "finding one from ground db", this time returning undefined 

请帮我解决这个问题。 在此先感谢

Taxel

回答

0

据我们调查(发现你的问题同时),这不是一个GroundDB错误。

目前我们正在类似的工作:也是一个科尔多瓦应用程序,试图保持脱机约30个不同的集合和使用React(但与Mantrajs)。因此,就像今天一样,我们几乎可以肯定,流星的功能就是删除Collections中的数据,我将尽力解释我自己:

似乎Meteor以某种方式检测到集合未被使用,几乎立即删除所有数据,然后GroundDB也从IndexedDB中删除数据。我们下载了GroundDB代码,将其添加到我们的Meteor项目并检查它,创建了以前的行为。

当前,我们试图找到一些方法来检测集合何时完全被擦除,Meteor Collection上的某种属性可能会告诉我们它将被清除,因此我们可以修复GroundDB代码并且不会删除IndexedDB数据在这种情况下。

我们正在尝试另一种选择是使用该组件:https://github.com/richsilv/meteor-dumb-collections

似乎非常相似,GroundDB但直到调用同步功能,因此它可能是更难使用它永远不会同步本地数据流星服务器对于我们和我们的30个系列:)

希望它可以帮助你。