-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #439
- Loading branch information
Showing
7 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var RxOld = require("rx"); | ||
var RxNew = require("../../../../index"); | ||
|
||
module.exports = function (suite) { | ||
|
||
var oldShareWithImmediateScheduler = RxOld.Observable.range(0, 25, RxOld.Scheduler.immediate).share(); | ||
var newShareWithImmediateScheduler = RxNew.Observable.range(0, 25).share(); | ||
|
||
return suite | ||
.add('old share with immediate scheduler', function () { | ||
oldShareWithImmediateScheduler.subscribe(_next, _error, _complete); | ||
}) | ||
.add('new share with immediate scheduler', function () { | ||
newShareWithImmediateScheduler.subscribe(_next, _error, _complete); | ||
}); | ||
|
||
function _next(x) { } | ||
function _error(e){ } | ||
function _complete(){ } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* globals describe, expect, it, hot, cold, expectObservable */ | ||
|
||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.share()', function (){ | ||
it('should share a single subscription', function (){ | ||
var subscriptionCount = 0; | ||
var obs = new Observable(function(observer){ | ||
subscriptionCount++; | ||
}); | ||
|
||
var source = obs.share(); | ||
|
||
expect(subscriptionCount).toBe(0); | ||
|
||
source.subscribe(); | ||
source.subscribe(); | ||
|
||
expect(subscriptionCount).toBe(1); | ||
}); | ||
|
||
it('should not change the output of the observable when successful', function (){ | ||
var e1 = hot('---a--^--b--c--d--e--|'); | ||
var expected = '---b--c--d--e--|'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
|
||
it('should not change the output of the observable when error', function (){ | ||
var e1 = hot('---a--^--b--c--d--e--#'); | ||
var expected = '---b--c--d--e--#'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
|
||
it('should not change the output of the observable when successful with cold observable', function (){ | ||
var e1 = cold('---a--b--c--d--e--|'); | ||
var expected = '---a--b--c--d--e--|'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
|
||
it('should not change the output of the observable when error with cold observable', function (){ | ||
var e1 = cold('---a--b--c--d--e--#'); | ||
var expected = '---a--b--c--d--e--#'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
|
||
it('should not change the output of the observable when never', function (){ | ||
var e1 = Observable.never(); | ||
var expected = '-'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
|
||
it('should not change the output of the observable when empty', function (){ | ||
var e1 = Observable.empty(); | ||
var expected = '|'; | ||
|
||
expectObservable(e1.share()).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Observable from '../Observable'; | ||
import publish from './publish'; | ||
|
||
export default function share<T>() : Observable<T> { | ||
return publish.call(this).refCount(); | ||
}; |