Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect documentation about operator share. #2937

Closed
mocheng opened this issue Oct 12, 2017 · 4 comments
Closed

Incorrect documentation about operator share. #2937

mocheng opened this issue Oct 12, 2017 · 4 comments
Labels
docs Issues and PRs related to documentation help wanted Issues we wouldn't mind assistance with.

Comments

@mocheng
Copy link

mocheng commented Oct 12, 2017

RxJS version:
5.4.3

Expected behavior:
The documentation of share should be correct.

Actual behavior:
The doc https://github.com/reactivex/rxjs/blob/master/src/operators/share.ts#L16 reads

This is an alias for .publish().refCount()

This is not correct. The operator share is actually a alias for .multicast(() => new Subject()).refCount(). There is difference between these two definition.

For .publish().refCount(), subscription after source completion will not re-execute the pipeline. However, for share(), subscription after source completion do re-execute the pipeline.

Check below example

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/publish';
import 'rxjs/add/operator/take';

const tick$ = Observable.interval(1000).take(3);
const sharedTick$ = tick$.publish().refCount();

sharedTick$.subscribe(value => console.log('observer 1: ' + value));
setTimeout(() => {
  sharedTick$.subscribe(value => console.log('observer 2: ' + value));
}, 4500);

Output of above code is:

observer 1: 0
observer 1: 1
observer 1: 2

And for share:

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/take';

const tick$ = Observable.interval(1000).take(3);
const sharedTick$ = tick$.share();

sharedTick$.subscribe(value => console.log('observer 1: ' + value));
setTimeout(() => {
  sharedTick$.subscribe(value => console.log('observer 2: ' + value));
}, 4500);

Above code has below output:

observer 1: 0
observer 1: 1
observer 1: 2
observer 2: 0
observer 2: 1
observer 2: 2
@benlesh
Copy link
Member

benlesh commented Oct 13, 2017

Yup... you're right. That is a miss on the docs.

cc/ @ladyleet

@benlesh benlesh added the help wanted Issues we wouldn't mind assistance with. label Oct 13, 2017
@crunchie84
Copy link
Contributor

I wanted to fix this but it seems that this is already (partly) addressed in https://github.com/ReactiveX/rxjs/blob/master/src/operator/share.ts but that is a different file (src/operator/xx vs src/operators/xx). Based on other files in those folders it is hard to discern where the documentation should reside.

@benlesh @ladyleet which of those paths should be the one containing the documentation of the operator?

@kwonoj kwonoj added the docs Issues and PRs related to documentation label Oct 17, 2017
seanhealy added a commit to seanhealy/rxjs that referenced this issue Oct 24, 2017
As suggested by ReactiveX#2937 this updates the docs on the share
operator to better reflect it's actual behaviour.
seanhealy added a commit to seanhealy/rxjs that referenced this issue Oct 24, 2017
As suggested by ReactiveX#2937 this updates the docs on the share
operator to better reflect it's actual behaviour.
staltz pushed a commit that referenced this issue Oct 24, 2017
PR #2990 

As suggested by #2937 this updates the docs on the share operator to better reflect it's actual behaviour.
@staltz
Copy link
Member

staltz commented Oct 24, 2017

Done with PR #2990

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Issues and PRs related to documentation help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

No branches or pull requests

5 participants