How to make a Meteor Collection non reactive depending on a url?

人盡茶涼 提交于 2019-12-25 04:28:30

问题


Hi I am building a magnetic poetry game with meteor which I am pretty green with.

http://test-magnets.meteor.com/

Currently it is collaborative it works great. I am now trying to have it so that you can play privately without people messing with your poems. I used Iron Router to generate a url based on the userID

router.js

Router.map(function() {
this.route('home', {
    path: '/'
});
var user = Meteor.userId();
this.route('private', {
    path: '/' + user
   });
});

I had the idea of using a fridgeId within the magnets. On the home collaborative are the fridgeId is 1. When you click on create my own, it changes the fridgeId to the same as the userId. I am assuming I need to do some sort of publishing and subscribing based on the fridgeId but not sure how to.

this switches the fridgeId to the user id

  'click #new-board': function() {
    var user = Meteor.userId();
    var magnet = Magnets.findOne();
    Magnets.update({_id: magnet._id}, {$set: {fridgeId: user}});
    return Magnets.find({fridgeId: user});
}

then this sets the fridgeId back to 1 on the home page

Template.private.events = {
   'click #group-play': function() {
    var magnet = Magnets.findOne();
    Magnets.update({_id: magnet._id}, {$set: {fridgeId: 1}});
    return Magnets.find({fridgeId: 1});
  }
};

current subscribe and publish

if (Meteor.isClient) {

Meteor.subscribe('magnets', function() {
    return Magnets.find();
 });
}

if (Meteor.isServer) {
  Meteor.publish('magnets', function() {
    return Magnets.find();
  });
 }

any suggestions would be greatly appreciated. Thanks

-John


回答1:


return Magnets.find({fridgeId: user},{reactive: false});


来源:https://stackoverflow.com/questions/28075985/how-to-make-a-meteor-collection-non-reactive-depending-on-a-url

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