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

refactor(Observable): Make 'protected' of Observable<T>._isScalar #522

Closed
wants to merge 1 commit into from
Closed

refactor(Observable): Make 'protected' of Observable<T>._isScalar #522

wants to merge 1 commit into from

Conversation

tetsuharuohzeki
Copy link
Contributor

This property should be accessed only from a derived class. There's no need to make this public.

This property should be accessed only from a derived class.
@staltz
Copy link
Member

staltz commented Oct 14, 2015

LGTM

@benlesh
Copy link
Member

benlesh commented Oct 14, 2015

I'm uncertain about this one... only because there are places where we're checking _isScalar on incoming observables (that just happen to be typed as any) at that point.

@benlesh
Copy link
Member

benlesh commented Oct 14, 2015

...meaning, if we ever decided to use proper typing in those points (and I'm not sure why we would, since they're internal to the library and not public APIs), having this as protected would be a problem.

Is there a reason why we want this change?

@tetsuharuohzeki
Copy link
Contributor Author

Is there a reason why we want this change?

Without this change, _isScalar field is visible as public field. I feel a developer will miss-touch this property, so we should hide _isScalar if we available to do it.
(Observable._subscribe has same problem, but we would need to define a new Symbol to hide it...)

@trxcllnt
Copy link
Member

@saneyuki it's perfectly acceptable to override Observable.prototype._subscribe if you know what you're doing ;-)

@tetsuharuohzeki
Copy link
Contributor Author

@trxcllnt

Yes, I don't think it's problem to override Observable.prototype._subscribe to create a new operator. I think it would be bad that Observable.prototype._subscribe could be accessed unconditionally from autocomplete or a developer who don't intend to create a new operator.

I feel it is reasonable idea to define a Symbol to access Observable.prototype._subscribe and export it to hook it.
(Umm, should we file a new issue to discuss about Observable.prototype._subscribe?)

@benlesh
Copy link
Member

benlesh commented Oct 15, 2015

@saneyuki .... I think my concern is that we access it "publicly" internally and I don't want to have TypeScript complaining at us or need to have to cast something as any to get things to build. I already feel like I jump through a lot of hoops for TypeScript's sake.

@benlesh
Copy link
Member

benlesh commented Oct 16, 2015

Sorry, @saneyuki, I think for now I'm going to close this PR. While it doesn't break anything, I'm not sure it fixes anything either. A third party may want to create a custom operator that optimizes for scalar observables which means checking _isScalar.

I really appreciate the thought and effort you've put into this. I'm just not sure it's the right move at this point.

... if we end up doing this later, you can totally say "I told you so" :)

@benlesh benlesh closed this Oct 16, 2015
@tetsuharuohzeki
Copy link
Contributor Author

A third party may want to create a custom operator that optimizes for scalar observables which means checking _isScalar.

Then, they uses/extends ScalarObservable if they need to check _isScalar?

@benlesh
Copy link
Member

benlesh commented Oct 17, 2015

PromiseObservable can also be _isScalar

@tetsuharuohzeki
Copy link
Contributor Author

@Blesh

Ah, my words is too short. My intent of the previous reply is that:

A third party who want to create a custom operator for them can check whether scalar/promise observable by using instanceof checking instead of _isScalar property. Would they really look _isScalar property?

I think basically we should not make public of internal items until if we meet unavoidable to expose them. I'm worrying it would be harder to stop exposed internals in early stage.

@benlesh
Copy link
Member

benlesh commented Oct 17, 2015

Since PromiseObservable can be optimized as "scalar" with _isScalar after it resolves the first time, and since PromiseObservable doesn't extend ScalarObservable, instanceof won't work.

However, maybe we can have PromiseObservable extend ScalarObservable... I don't know, I haven't put much thought into it.

@benlesh
Copy link
Member

benlesh commented Oct 17, 2015

... probably not though.

@tetsuharuohzeki
Copy link
Contributor Author

since PromiseObservable doesn't extend ScalarObservable, instanceof won't work.

This (specialized) pass would work as instanceof checking.

if (observable instanceof ScalarObservable || observable instanceof PromiseObservable) {
   ...
}

@tetsuharuohzeki
Copy link
Contributor Author

...I meant it on my replying.

@benlesh
Copy link
Member

benlesh commented Oct 19, 2015

I'll investigate it. I don't want to make this change right now. Other things would need to change. For example, you can't treat PromiseObservables the same as scalars until they've resolved once... so it would be more like:

if (observable instanceof ScalarObservable || (observable instanceof PromiseObservable && observable.isResolved)) {
  ...
}

I'm unsure if that's going to be more efficient than just checking isScalar.

Also, we'd have to publish ScalarObservable and PromiseObservable with the global package, otherwise people won't be able to test them unless they're using a module system so they can pull those types in.

@tetsuharuohzeki
Copy link
Contributor Author

@Blesh

Okay. I accept your decision. Thank you for a long discussion.

@tetsuharuohzeki tetsuharuohzeki deleted the isscalar branch October 19, 2015 08:27
@benlesh
Copy link
Member

benlesh commented Oct 20, 2015

<3 @saneyuki

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants