-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Proposal : remove circular reference using ambient merge #909
Conversation
- remove circular references using microsoft/TypeScript#3332, parents are references children via ambient interfaces and let compiler merges it
@@ -89,7 +90,7 @@ export class Observable<T> implements CoreOperators<T> { | |||
let subscriber: Subscriber<T>; | |||
|
|||
if (observerOrNext && typeof observerOrNext === 'object') { | |||
if (observerOrNext instanceof Subscriber || observerOrNext instanceof Subject) { | |||
if (observerOrNext instanceof Subscriber) { //|| observerOrNext instanceof Subject) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part where regresses #863, ambient declaration of Subject
cannot check its type via instanceof
since it's interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
if (observerOrNext instanceof Subscriber ||
(typeof (<Subject>observerOrNext).next === 'function' && typeof (<Subject>observerOrNext).subscribe === 'function')) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only reason for the explicit <Subject>
is to make the code tool-friendly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, need to cast <any>
instead of Subject
(since compile time imported ambient declaration does not have interfaces) but this works, thanks for pointing out. I was just spending time in opposite way of bringing interface check availability to runtime..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an alternative PR for this particular bit here #912
Due to regression, this PR does not passes travis and it's expected. |
@@ -0,0 +1 @@ | |||
export interface ConnectableObservable<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this declarations could be single module such as
ambient.ts
export interface A{}
export interface B{}
export interface C{}
to allow single import to declarations like
import {A,B,C} from 'ambient'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, make these all into one file.
Note : this change has side effect of reducing build time speed. On travis, numbers are below (may vary per run though) without PR(cjs)
with PR(cjs)
|
I'll leave this PR as is for now to get opinions of direction itself, once it's agreed to go will update PR accordingly. |
Yeah, I think we can probably close this one for now, since we no longer have the circular reference issue. I really appreciate the thought and hard work here though. It's an idea I'll have to remember if we do run into the circular reference issue again. |
Thanks again, @kwonoj |
It is cool to have changes landed to resolve issue. Thanks for taking time to reviewing this, @Blesh :) |
Proposal : not to be merged yet
This PR is proposal to resolve #899, via ambient declaration merging introduced in typescript (microsoft/TypeScript#3332).
In this PR, for any parents requires to have declaration of inherited childs, it imports ambient declarations instead of actual implementation of child to remove circular dependencies. Since reference to child from parents is mostly for type declaration only, this doesn't affect actual functionality in general.
Still for some cases functionality's breaking, such as this PR regresses #863 due to failed to check type of
Subject
since ambient declaration doesn't allow type checking. Yet this is proposal, PR does not include those refactoring but only include necessary changes.