-
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
refactor(Subject): introduce interface to Subject #2279
Conversation
18b729c
to
960a641
Compare
So this is only not a breaking change because TS is structurally typed? Can you clarify specifically what is more clear to users with this change? So they don't have all the other extraneous signatures? |
It is not breaking since this PR only extracts out interface shape from existing Subject implementation. It isn't being actively used elsewhere, so while it gives clarity who reads interface of Subject but actual type inferences related with subject won't benefit hugely. Previous PR was actually changing runtime behavior to prevent unintended interface access though. |
@kwonoj hmmm but isn't // some user code that assumes Subject, not ISubject
function gimmieStuff(stuff: Subject) {}
let stuff = Subject.create(...);
gimmieStuff(stuff); |
@jayphelps , it is. My comment is based on most of subject creation is currently recommended via instantiation but not by static creation method. Anyway there are opened issue for definition of static subject creation method. #2004 too. |
src/Subject.ts
Outdated
@@ -16,40 +16,43 @@ export class SubjectSubscriber<T> extends Subscriber<T> { | |||
} | |||
} | |||
|
|||
export interface ISubject<T> extends ISubscription, Observable<T> { | |||
readonly observers: ReadonlyArray<Observer<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.
this is sort of an implementation detail of Subject
.
src/Subject.ts
Outdated
export interface ISubject<T> extends ISubscription, Observable<T> { | ||
readonly observers: ReadonlyArray<Observer<T>>; | ||
readonly closed: boolean; | ||
readonly isStopped: boolean; |
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.
isStopped
is also an implementation detail.
src/Subject.ts
Outdated
@@ -16,40 +16,43 @@ export class SubjectSubscriber<T> extends Subscriber<T> { | |||
} | |||
} | |||
|
|||
export interface ISubject<T> extends ISubscription, Observable<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.
Why does ISubject
not extend an Observer
interface as well?
src/Subject.ts
Outdated
/** | ||
* @class Subject<T> | ||
*/ | ||
export class Subject<T> extends Observable<T> implements ISubscription { | ||
export class Subject<T> extends Observable<T> implements ISubject<T> { | ||
|
||
[$$rxSubscriber]() { | ||
return new SubjectSubscriber(this); | ||
} | ||
|
||
observers: Observer<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.
should probably be protected.
src/Subject.ts
Outdated
closed = false; | ||
|
||
isStopped = false; |
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.
should probably be protected
So where are we returning |
If an interface being extracted, why doesn't it follow the classic definition of the Subject where it is just simply that: interface ISubject<T> extends /*IObserver<T>*/ Observer<T>, /*IObservable<T>*/ Subscribable<T> { } all other attributes would make the abstraction leaking (as do |
cc @kwonoj ... I'm generally in favor of this change... can you make the changes I've requested? Or rebutt them I guess? haha. :) |
@Blesh oh yes, I just forgot this one :/ and I think this can be definitely minor, as it doesn't breaking existing behavior in most cases. |
960a641
to
a1d5862
Compare
Updated PR as suggested. /cc @Blesh |
Seems like a MINOR. Adds feature with backwards compat. |
So, making interface clear makes cannot build this, as some of internal implementation (SubjectSubscription, COnnectableObservable) was relying on incorrectly publicly-exposed ones. :/ |
a1d5862
to
3e32a35
Compare
3e32a35
to
1133b66
Compare
@kwonoj.. this seems to have gone stale. Can we close it? |
I still believe this need to be landed in master in some way, but this PR itself has too diverged. Closing it and let me create other PR based on TOT. |
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. |
Description:
This PR enhances type definition of
subject
separated from #2233, similar to #2249.This change introduces new interface
ISubject<T>
have more clear type definition regarding its properties, and let static creation method returns interface instead of actual implementation type.Related issue (if exists):