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
fix(TestScheduler): remove applyMixins use #7325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
import { Observable } from '../Observable'; | ||
import { Subscription } from '../Subscription'; | ||
import { Scheduler } from '../Scheduler'; | ||
import { TestMessage } from './TestMessage'; | ||
import { SubscriptionLog } from './SubscriptionLog'; | ||
import { SubscriptionLoggable } from './SubscriptionLoggable'; | ||
import { applyMixins } from '../util/applyMixins'; | ||
import { Subscriber } from '../Subscriber'; | ||
import { observeNotification } from '../Notification'; | ||
import { SchedulerLike, TeardownLogic } from '../types'; | ||
import { logSubscribedFrame, logUnsubscribedFrame, SubscriptionLog } from './subscription-logging'; | ||
|
||
export class ColdObservable<T> extends Observable<T> implements SubscriptionLoggable { | ||
export class ColdObservable<T> extends Observable<T> { | ||
public subscriptions: SubscriptionLog[] = []; | ||
scheduler: Scheduler; | ||
// @ts-ignore: Property has no initializer and is not definitely assigned | ||
logSubscribedFrame: () => number; | ||
// @ts-ignore: Property has no initializer and is not definitely assigned | ||
logUnsubscribedFrame: (index: number) => void; | ||
logSubscribedFrame = logSubscribedFrame; | ||
logUnsubscribedFrame = logUnsubscribedFrame; | ||
|
||
constructor(public messages: TestMessage[], scheduler: Scheduler) { | ||
super(function (this: Observable<T>, subscriber: Subscriber<any>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this super argument out to just be declared as a method. It's just less complicated. |
||
const observable: ColdObservable<T> = this as any; | ||
const index = observable.logSubscribedFrame(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In particular, in some environments with CJS and ES2022, applyMixins was not adding the mixing properties to the prototype, and we were getting errors here. |
||
const subscription = new Subscription(); | ||
subscription.add( | ||
new Subscription(() => { | ||
observable.logUnsubscribedFrame(index); | ||
}) | ||
); | ||
observable.scheduleMessages(subscriber); | ||
return subscription; | ||
}); | ||
this.scheduler = scheduler; | ||
protected _subscribe(subscriber: Subscriber<any>): TeardownLogic { | ||
const index = this.logSubscribedFrame(); | ||
const subscription = new Subscription(); | ||
subscription.add( | ||
new Subscription(() => { | ||
this.logUnsubscribedFrame(index); | ||
}) | ||
); | ||
this.scheduleMessages(subscriber); | ||
return subscription; | ||
} | ||
|
||
constructor(public messages: TestMessage[], public scheduler: SchedulerLike) { | ||
super(); | ||
} | ||
|
||
scheduleMessages(subscriber: Subscriber<any>) { | ||
|
@@ -39,7 +34,10 @@ export class ColdObservable<T> extends Observable<T> implements SubscriptionLogg | |
subscriber.add( | ||
this.scheduler.schedule( | ||
(state) => { | ||
const { message: { notification }, subscriber: destination } = state!; | ||
const { | ||
message: { notification }, | ||
subscriber: destination, | ||
} = state!; | ||
observeNotification(notification, destination); | ||
}, | ||
message.frame, | ||
|
@@ -49,4 +47,3 @@ export class ColdObservable<T> extends Observable<T> implements SubscriptionLogg | |
} | ||
} | ||
} | ||
applyMixins(ColdObservable, [SubscriptionLoggable]); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
interface SubscriptionLoggingProps { | ||
subscriptions: SubscriptionLog[]; | ||
scheduler: { now(): number }; | ||
} | ||
|
||
export class SubscriptionLog { | ||
constructor(public subscribedFrame: number, public unsubscribedFrame: number = Infinity) {} | ||
} | ||
|
||
export function logUnsubscribedFrame(this: SubscriptionLoggingProps, index: number) { | ||
const subscriptionLogs = this.subscriptions; | ||
const oldSubscriptionLog = subscriptionLogs[index]; | ||
subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now()); | ||
} | ||
|
||
export function logSubscribedFrame(this: SubscriptionLoggingProps): number { | ||
this.subscriptions.push(new SubscriptionLog(this.scheduler.now())); | ||
return this.subscriptions.length - 1; | ||
} |
This file was deleted.
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.
Instead of mixins I'm just adding the methods as function properties on the classes.