2016-05-10 4 views
0

非常に似ていたので、2つの出版物を1つにまとめました。どちらもカーソルのセットを返しました。私は低レベルのAPIでそれらを書き直し、データの削除をある程度制御しました。Meteor publicationsのthis.readyはトリガーしません

私の問題は、私が完全に無視する理由で、サブスクリプションonReadyコールバックは決して引き起こされないということです。私は同様の方法でデータを公開し、それは完全に動作する私のアプリで他の低レベルのpubsubを持っている。

サーバー上で、すべてのログが正しく表示され、エラーは表示されません。パブリケーションは正しく実行され、データはクライアントに効果的に送信されます。 クライアントでは、onReadyまたはonErrorコールバックがトリガーされません。

出版:

Meteor.publish("getTalkthread", function (thread_id) { 
    unblock(this); 

    console.log("start"); 

    let uids = tags = corrections = [], 
      self = this; 

    let posts_cursor = Modules.both.queryGet({ 
       type    : 'posts', 
       method   : 'find', 
       query    : { $or: [ 
          { _id: thread_id }, 
          { parent: thread_id } 
          ] 
         }, 
       projection : { sort : { _id: 1 }, 
               limit : 50 
              } 
      }); 

    let posts_array = posts_cursor.fetch(), 
     posts_ids = posts_array.map(e => (e._id)); 

    //console.log("fetched posts", posts_array); 

    let corrs_cursor = Modules.both.queryGet({ 
       type    : 'corrections', 
       method   : 'find', 
       query    : { talkId: { $in: posts_ids } }, 
       projection : { sort : { _id: 1 }, 
               limit : 50 
              } 
      }); 

    let corrs_array = corrs_cursor.fetch(); 

    //console.log("fetched corrs", corrs_array); 

    let posts_authors = posts_array.map(e => (e.owner)), 
     corrs_authors = corrs_array.map(e => (e.owner)); 

    let users_ids = _.union(posts_authors, corrs_authors); 

    let users_cursor = Modules.both.queryGet({ 
      type    : 'users', 
      method   : 'find', 
      query    : { _id: { $in: users_ids } }, 
      projection : { sort  : { date: -1 }, 
          limit  : 100, 
          fields : USER_PROFILE_FIELDS_ 
         } 
     }); 

    //console.log("fetched users", users_cursor.fetch()); 

    let observers = {}; 

    observers.posts = posts_cursor.observeChanges({ 
     added  : (id, fields) => { console.log("post added " + id); self.added ("posts", id, fields); }, 
     changed : (id, fields) => { console.log("post changed " + id); self.changed("posts", id, fields); }, 
     removed : (id)     => { 
      console.log("test"); 
     if (id != thread_id) { 
       console.log(true); 
     self.removed("posts removed " + id); 
     } 
    } 
    }); 

    observers.users = users_cursor.observeChanges({ 
     added  : (id, fields) => { console.log("user added " + id); self.added ("users", id, fields); }, 
     changed : (id, fields) => { console.log("user changed " + id); }, 
     removed : (id)     => { console.log("user removed " + id); } 
    }); 

    observers.corrs = corrs_cursor.observeChanges({ 
     added  : (id, fields) => { console.log("corr added " + id); self.added ("corrections", id, fields); }, 
     changed : (id, fields) => { console.log("corr changed " + id); self.changed("corrections", id, fields); }, 
     removed : (id)     => { console.log("corr removed " + id); self.removed("corrections", id);    } 
    }); 

    console.log("observers created"); 

    this.ready(); 

    self.onStop(() => { 
     observers.posts.stop(); 
     observers.users.stop(); 
     observers.corrs.stop(); 
    }); 

    console.log("end"); 

}); 

サブスクリプション:

 console.log("sub"); 
     self.subscribe("getTalkthread", id, self.rerun.get()), { 
     onReady: function() { 
      console.log("READY"); 
      if (!Posts.findOne({ _id: id })) { 
      $("#404NotFound").show(); 
      $("#isoContent").hide(); 
      } else if (Posts.findOne(id)) { 
      $("#isoContent").show(); 
      } 
      $("#spin").hide(); 
     }, 
     onError: function() { 
      console.log("ERROR"); 
      $("#spin").hide(); 
      $("#404NotFound").show(); 
      $("#isoContent").hide(); 
     } 
     }; 

クライアントページが正しくレンダリングされますが、DOM操作は、コンテンツの表示を禁止、起動されません。誰かが私がここで間違っていることを見ていますか?あなた

EDIT

ありがとう:

私はどんな理由であれ、問題は同じで、3つのカーソルの配列を返すようにしようとした、と。しかし、なぜ私は見ません。

+0

「ブロックを解除する(これ);」はわかりません。出版物に 'this.unblock()'を書くことができるパッケージがあります。それは、問題が何であるかわからない場合は –

+0

です。私はちょうど 'this.ready'と呼ばれるブランクの出版物でテストして、あなたのコールバックがクライアント上で呼び出されるかどうかを見ます。ゆっくりと出版物を作ります。 –

+0

そして、変数の名前の下線は、私の目を傷つけます。 JSではcamelCaseを使用します。これはPythonではありません –

答えて

0

なぜ私は理解できませんが、自然のMeteor.subscribeではなくArunodaのSubsManagerを使用して問題を解決しました。

関連する問題