Subscription manager doesn't update collection after new subscription

与世无争的帅哥 提交于 2019-12-12 20:13:57

问题


In my Meteor application I have this situation in which I have a 'Settings' collection only on the client. So the publish function is:

Meteor.publish('settings', function (option) {

    this.added("settings", "settings", {
        bar: true,
        foo: { .... }
    });

    this.ready();
});

Initially I subscribe like:

waintOn: function () {
    return subs.subscribe('settings')
}

But when the route changes I subscribe again like

return subs.subscribe('settings', 10);

After this I see that the publish function runs, but on the client nothing happens. For some reason the server thinks that the data did not change and decides to do nothing. So the question is how can I tell Meteor that the data has changed so it sends the data to the client. If the problem is completely different, I'm also very interested!!

UPDATE: the publish function might look like this:

Meteor.publish('settings', function (option) {
    var list;

    if (option === 10) {
       list = [1,2,3,4,5];
    }

    this.added("settings", "settings", {
        bar: true,
        foo: list
    });

    this.ready();
});

UPDATE2: Expected solution:

var isNew = true;
Meteor.publish('settings', function () {

    if(isNew) {
        this.added("settings", "settings", {
            bar: true,
            foo: list
        });
        isNew = false;
    }
    else {
        this.changed('settings', 'settings', {.....});
    }

    this.ready();
});

It would even be better if there was a function like this.exists('settings', 'settings') because the isNew variable feels a bit like a hack!

Anyway, I have it working now as follows:

 try { 
     this.removed('settings', 'settings');
 } catch(e){}

 this.added('settings', 'settings', {...});
 ...

来源:https://stackoverflow.com/questions/24825369/subscription-manager-doesnt-update-collection-after-new-subscription

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!