问题使React-Komposer对多个订阅具有反应性

时间:2016-06-08 05:46:45

标签: javascript meteor reactjs

我正在使用流星厨师基地,而且我在使用react-komposer时遇到了反应问题。我有一个订阅调用,它从url(lectureId,courseId)获取id,首先查找(并创建,如果需要)带有这些id的userLecture文档和它用于获取当前Question订阅的currentQuestion字段。我稍后更新了currentQuestion id但问题订阅在硬页面刷新之前不会更新。当输入实际没有变化时,如何才能使该订阅被动?

const composer = (params, onData) => {
  let subscription = Meteor.subscribe('questionFromSlugs', params.courseSlug, params.lectureSlug);
  if (subscription.ready()) {
    const question = Questions.findOne();
    const userLecture = UserLecture.findOne();

    onData(null, { question });
  }
};
export default composeWithTracker(composer, Loading)(QuizQuestion);

这是流星订阅:

Meteor.publish('questionFromSlugs', function(courseSlug, lectureSlug){
  check(courseSlug, String);
  check(lectureSlug, String);
  check(this.userId, String);
  let user  = this.userId;
  let lecture = Lectures.findOne({courseSlug: courseSlug, slug: lectureSlug});
  let course = Courses.findOne({slug: courseSlug});

  if (lecture != null && course != null) {

    var thisLectureScore = UserLecture.find({
      userId: user,
      lectureId: lecture._id
    }).count();

    if (thisLectureScore == 0){
      UserLecture.insert({
        userId: user,
        courseId: course._id,
        lectureId: lecture._id,
        lectureScore: 0,
        currentLevel: 1
      });
    }

    let userLecture = UserLecture.findOne({
      userId: user,
      courseId: course._id,
      lectureId: lecture._id
    });

    if (userLecture != null){
      return [
        Questions.find({_id: userLecture.currentQuestionId}),
        UserLecture.find({
          userId: user,
          courseId: course._id,
          lectureId: lecture._id
        })
      ]
    }
  }
});

1 个答案:

答案 0 :(得分:0)

你知道它不会改变吗?我有类似的问题。它隐藏在我填充视图的方式中。你用的是什么ui框架?我觉得有所反应。请提供我的观点,我想我知道你的问题的解决方案。