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

Proposal : remove circular reference using ambient merge #909

Closed
wants to merge 1 commit into from

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Dec 7, 2015

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.

- 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) {
Copy link
Member Author

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.

Copy link
Contributor

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')) {

Copy link
Contributor

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.

Copy link
Member Author

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..

Copy link
Member

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

@kwonoj
Copy link
Member Author

kwonoj commented Dec 7, 2015

Due to regression, this PR does not passes travis and it's expected.

@@ -0,0 +1 @@
export interface ConnectableObservable<T> {}
Copy link
Member Author

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'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member

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.

@kwonoj
Copy link
Member Author

kwonoj commented Dec 7, 2015

Note : this change has side effect of reducing build time speed. On travis, numbers are below (may vary per run though)

without PR(cjs)

Files:             280
Lines:           27854
Nodes:          128684
Identifiers:     42695
Symbols:       8453476
Types:          477658
Memory used:   766295K
I/O read:        0.02s
I/O write:       0.07s
Parse time:      0.55s
Bind time:       0.33s
Check time:     14.64s
Emit time:       1.00s
Total time:     16.52s

with PR(cjs)

Files:             284
Lines:           27853
Nodes:          128728
Identifiers:     42705
Symbols:       8038078
Types:          193698
Memory used:   282858K
I/O read:        0.03s
I/O write:       0.06s
Parse time:      0.81s
Bind time:       0.60s
Check time:      8.22s
Emit time:       0.92s
Total time:     10.56s

@kwonoj
Copy link
Member Author

kwonoj commented Dec 7, 2015

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.

@benlesh
Copy link
Member

benlesh commented Dec 7, 2015

@kwonoj, I like what you're doing with the ambient interface declarations here. We can probably use that. I have an alternative PR for fixing the Subject as a subscriber issue here #912. We can probably merge both of these PRs if you want to remove the changes you made to subscribe here.

@kwonoj
Copy link
Member Author

kwonoj commented Dec 7, 2015

@Blesh Just saw PR for rxSubscriber and seems that resolves one of failings to deal with Subject above gracefully. Once PR #912 is merged, I'll update this PR accordingly by utilizing those changes.

@kwonoj
Copy link
Member Author

kwonoj commented Dec 8, 2015

Seems #912 solves circular reference and this PR might not have much values to be added except few side effect like reduce build time. Once got confirmation from @Blesh , I'll close this without merge.

@benlesh
Copy link
Member

benlesh commented Dec 8, 2015

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.

@benlesh benlesh closed this Dec 8, 2015
@benlesh
Copy link
Member

benlesh commented Dec 8, 2015

Thanks again, @kwonoj

@kwonoj kwonoj deleted the refactor-ambientmerge branch December 8, 2015 01:47
@kwonoj
Copy link
Member Author

kwonoj commented Dec 8, 2015

It is cool to have changes landed to resolve issue. Thanks for taking time to reviewing this, @Blesh :)

@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.

Circular reference between Observable and others
3 participants