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

Rename sample operators to inspect, reimplement sample operator #1053

Closed
benlesh opened this issue Dec 14, 2015 · 13 comments
Closed

Rename sample operators to inspect, reimplement sample operator #1053

benlesh opened this issue Dec 14, 2015 · 13 comments
Assignees

Comments

@benlesh
Copy link
Member

benlesh commented Dec 14, 2015

Per some offline discussion with @headinthebox, @mattpodwysocki and @staltz... the current implementation of sample as discussed in #150 is probably incorrect.

Basically, in the original sample operator ala RxJS 4, the emission of a value meant that a new value had arrived on the source. If the notifier notified, and a new value hadn't arrived, nothing would be emitted. This means the very emission of the value has some meaning/connotations WRT the source observable.

... that said ... I think @staltz raised some interesting points about how people might expect a sample operator to work, or needs those people might have.

... so rather than throw away the current sample and sampleTime implementations, I'd like to rename them to inspect and inspectTime and then reimplement the sample operators in RxJS 4's likeness.

@staltz
Copy link
Member

staltz commented Dec 14, 2015

I'd question the usefulness of both inspect and sample flavors, since we're just adding more operators.

It seems easier to keep in core only radically important operators (like mergeMap, scan, map, take...), than to bloat core with many operators.

@staltz
Copy link
Member

staltz commented Dec 14, 2015

@Blesh There's also the issue with sample/inspect that the completion of the sampler Observable should "sample" the sampled Observable, like Erik mentioned. That might be important for beta.

@benlesh
Copy link
Member Author

benlesh commented Dec 14, 2015

There's also the issue with sample/inspect that the completion of the sampler Observable should "sample" the sampled Observable, like Erik mentioned. That might be important for beta.

👍 good catch. I don't think I included this in my PR. I'll add that.

@benlesh
Copy link
Member Author

benlesh commented Dec 14, 2015

I'd question the usefulness of both inspect and sample flavors, since we're just adding more operators.

As long as inspect is in KitchenSink, and we're going with this modular design. I don't think it matters.

If it came down to removing one, though, I'd remove inspect. Only because it could be composed from sample, where the reverse isn't really possible.

@staltz
Copy link
Member

staltz commented Dec 14, 2015

I'm curious, how would inspect be written using sample and others?

@benlesh
Copy link
Member Author

benlesh commented Dec 14, 2015

Thinking quickly: Something like... notifier.withLatestFrom(source.sample(notifier), (_, a) => a)? That might not be perfect, but it's an approximation, I'd guess. The emitting on completion behavior of sample might make it weird, but you could compose around that too.

@staltz
Copy link
Member

staltz commented Dec 14, 2015

Why not just notifier.withLatestFrom(source, (_, a) => a)?

@benlesh
Copy link
Member Author

benlesh commented Dec 14, 2015

Why not just notifier.withLatestFrom(source, (_, a) => a)?

I don't know? lol.

@staltz
Copy link
Member

staltz commented Dec 15, 2015

Seriously, I could run all inspect tests replaced with withLatestFrom. If everything works fine, we could remove inspect.

@staltz
Copy link
Member

staltz commented Dec 15, 2015

Just FYI, withLatestFrom needs also the addition of last() in order to get the completion semantics (almost) right:

  it('should get inspections when the notifier emits', function () {
    var e1 =   hot('----a-^--b----c----d----e----f----|          ');
    var e1subs =         '^                           !          ';
    var e2 =   hot(      '-----x----------x----------x----------|');
    var e2subs =         '^                           !          ';
    var expected =       '-----b----------d----------f|          ';

    var result = e2.withLatestFrom(e1, function (a, b) { return b; }).takeUntil(e1.last());

    expectObservable(result).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
    expectSubscriptions(e2.subscriptions).toBe(e2subs);
  });

I don't know how useful it is to have the completion semantics of inspect, but since we just introduced this operator, I suppose people don't depend on how inspect works. For that reason it's probably better to kill inspect and recommend instead withLatestFrom if anyone needs something similar to inspect. Just my opinion.

@headinthebox
Copy link

Agreed.

@benlesh
Copy link
Member Author

benlesh commented Dec 15, 2015

I'm fine with that.

staltz added a commit to staltz/RxJSNext that referenced this issue Dec 17, 2015
Remove inspect and inspectTime operators from this library, since they are unnecessary and don't
exist in previous versions of RxJS.

This change was suggested in issue ReactiveX#1053.

BREAKING CHANGES:
`inspect` and `inspectTime` were removed. Use `withLatestFrom` instead.
staltz added a commit to staltz/RxJSNext that referenced this issue Dec 17, 2015
Remove inspect and inspectTime operators from this library, since they are unnecessary and don't
exist in previous versions of RxJS.

This change was suggested in issue ReactiveX#1053.

BREAKING CHANGE:
`inspect` and `inspectTime` were removed. Use `withLatestFrom` instead.
kwonoj pushed a commit that referenced this issue Dec 22, 2015
Remove inspect and inspectTime operators from this library, since they are unnecessary and don't
exist in previous versions of RxJS.

This change was suggested in issue #1053.

BREAKING CHANGE:
`inspect` and `inspectTime` were removed. Use `withLatestFrom` instead.
@lock
Copy link

lock bot commented Jun 7, 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 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants