2016-04-14 5 views
7

私はこのチュートリアルhttps://egghead.io/lessons/rxjs-creating-an-observableを使用していますが、これは2.5.2 rxjsバージョンを参照しています。最新のrxjsを参照するときにrxjsエラーが発生する

私は、最新のrx.umd.js[email protected]"からNPMパッケージ<script src="node_modules/rxjs/bundles/rx.umd.js"></script> を参照すると、ここで私が実行しようとしていますコードでいます:ここで

console.clear(); 

var source = Rx.Observable.create(function(observer){ 
    setTimeout(function() { 
     console.log('timeout hit'); 
     observer.onNext(42); 
     observer.onCompleted(); 
    }, 1000); 

    console.log('started'); 
}); 

var sub = source.subscribe(function(x) { 
    console.log('next ' + x); 
}, function(err) { 
    console.error(err); 
}, function() { 
    console.info('done'); 
}); 

setTimeout(function() { 
    sub.dispose() 
}, 500); 

は、私が取得していますコンソール出力です。

Console was cleared 
script.js:10 started 
script.js:22 Uncaught TypeError: sub.dispose is not a function 
script.js:5 timeout hit 
script.js:6 Uncaught TypeError: observer.onNext is not a function 

plunker:https://plnkr.co/edit/w1ZJL64b8rnA92PVuEDF?p=catalogue

がrxjs 5 APIでrxjs 2.5とobserver.onNext(42);sub.dispose()大きく異なるのは、サポート長くはないのですか?

答えて

7

そうです。パフォーマンスを向上させるためにRxJS 5を書き換え、ES7 Observable仕様にも準拠しています。 GithubのRxJS 4->5 migration pageをチェックしてください。

はここで働い例です:メソッドの多くは、名前を変更してしまった

// Create new observable 
const one = Observable.of(1,2,3); 

// Subscribe to it 
const oneSubscription = one.subscribe({ 
    next: x => console.log(x), 
    error: e => console.error(e), 
    complete:() => console.log('complete') 
}); 

// "Dispose"/unsubscribe from it 
oneSubscription.unsubscribe(); 

が、API自体はに移行するのは非常に簡単です。

+0

https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#observer-interface-changes-also-subjects – Cody

関連する問題