2016-07-16 6 views

答えて

2

UPDATE

それは私がちょうどplunkerと角度2で帆を使用する方法の完全な例を与えることができなかったことを私にイライラので、私はgithub repoを作成し、そのこれがどのように機能するかについての完全な図を提供します。


あなたがリンクした関連する質問がどのようにゾーンパスを導くかがわかります。ただし、ゾーンを手動で変更することなく、これらのすべてを一緒に接続することができます。 Hereは、Angular2を使ってsails.ioをプランナーに実装する方法の例です。これは、RxJSを使用してobservableのタイプを作成するのに役立ちます。またAngular2 change detectionの異なるバージョンを実装する必要があります(これはすべてプランナーに実装されています)。

私はあなたのlinked questionへの私の答えでもう少し詳しく説明します。

あなたのサブ質問については、ストリームを統合する方法があるかどうか分かりませんが、私はRxJSの意図の1つがコールバックの使用を減らすことだと考えています。

プランナーからのサービスでsails.ioを実装する方法の抜粋。

constructor() { 
    this._ioMessage$ = <Subject<{}>>new Subject(); 
    //self is the window object in the browser, the 'io' object is actually on global scope 
    self.io.sails.connect('https://localhost:1337');//This fails as no sails server is listening and plunker requires https 
    this.listenForIOSubmission(); 
} 

get ioMessage$(){ 
    return this._ioMessage$.asObservable(); 
} 

private listenForIOSubmission():void{ 
    if(self.io.socket){//since the connect method failed in the constructor the socket object doesn't exist 
    //if there is a need to call emit or any other steps to prep Sails on node.js, do it here. 
    self.io.socket.on('success', (data) => {//guessing 'success' would be the eventIdentity 
     //note - you data object coming back from node.js, won't look like what I am using in this example, you should adjust your code to reflect that. 
     this._ioMessage$.next(data);//now IO is setup to submit data to the subscribbables of the observer 
    }); 
    } 
} 
+0

文法「」は償却されると思います。新しい構文は 'this._ioMessage $ = Subject Subject()として件名<{}>;' – ktamlyn

+0

です。これを試してみます。 – ktamlyn

関連する問題