8000 feat(Subject.create): Removed the deprecated `Subject.create` method. · ReactiveX/rxjs@d62ce6e · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit d62ce6e

Browse files
committed
feat(Subject.create): Removed the deprecated Subject.create method.
BREAKING CHANGE: Removed the deprecated `Subject.create` method. If you need to create an object that is "half Observable, half Observer", you'll need to either bolt `next`, `error`, and `complete` handlers onto an `Observable` and property type the return... or you'll need to create your own class that is backed by an `Observable`. In any case, if the `Observer` and the `Observable` are so unrelated that you have to bolt them together, you're probably better off with those two objects separately. This is why `Subject.create` has been deprecated for so long.
1 parent ae005b4 commit d62ce6e

File tree

2 files changed

+0
-163
lines changed

2 files changed

+0
-163
lines changed

packages/rxjs/spec/Subject-spec.ts

-126
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import { Subject, Observable, AsyncSubject, Observer, of, config, Subscription, Subscriber, noop, operate } from 'rxjs';
3-
import { AnonymousSubject } from 'rxjs/internal/Subject';
43
import { delay } from 'rxjs/operators';
54
import { TestScheduler } from 'rxjs/testing';
65
import { observableMatcher } from './helpers/observableMatcher';
@@ -448,104 +447,6 @@ describe('Subject', () => {
448447
expect(subject.observed).to.equal(false);
449448
});
450449

451-
it('should have a static create function that works', () => {
452-
expect(Subject.create).to.be.a('function');
453-
const source = of(1, 2, 3, 4, 5);
454-
const nexts: number[] = [];
455-
const output: any[] = [];
456-
457-
let error: any;
458-
let complete = false;
459-
let outputComplete = false;
460-
461-
const destination = {
462-
closed: false,
463-
next: function (x: number) {
464-
nexts.push(x);
465-
},
466-
error: function (err: any) {
467-
error = err;
468-
this.closed = true;
469-
},
470-
complete: function () {
471-
complete = true;
472-
this.closed = true;
473-
},
474-
};
475-
476-
const sub: Subject<any> = Subject.create(destination, source);
477-
478-
sub.subscribe({
479-
next: function (x: number) {
480-
output.push(x);
481-
},
482-
complete: () => {
483-
outputComplete = true;
484-
},
485-
});
486-
487-
sub.next('a');
488-
sub.next('b');
489-
sub.next('c');
490-
sub.complete();
491-
492-
expect(nexts).to.deep.equal(['a', 'b', 'c']);
493-
expect(complete).to.be.true;
494-
expect(error).to.be.a('undefined');
495-
496-
expect(output).to.deep.equal([1, 2, 3, 4, 5]);
497-
expect(outputComplete).to.be.true;
498-
});
499-
500-
it('should have a static create function that works also to raise errors', () => {
501-
expect(Subject.create).to.be.a('function');
502-
const source = of(1, 2, 3, 4, 5);
503-
const nexts: number[] = [];
504-
const output: number[] = [];
505-
506-
let error: any;
507-
let complete = false;
508-
let outputComplete = false;
509-
510-
const destination = {
511-
closed: false,
512-
next: function (x: number) {
513-
nexts.push(x);
514-
},
515-
error: function (err: any) {
516-
error = err;
517-
this.closed = true;
518-
},
519-
complete: function () {
520-
complete = true;
521-
this.closed = true;
522-
},
523-
};
524-
525-
const sub: Subject<any> = Subject.create(destination, source);
526-
527-
sub.subscribe({
528-
next: function (x: number) {
529-
output.push(x);
530-
},
531-
complete: () => {
532-
outputComplete = true;
533-
},
534-
});
535-
536-
sub.next('a');
537-
sub.next('b');
538-
sub.next('c');
539-
sub.error('boom');
540-
541-
expect(nexts).to.deep.equal(['a', 'b', 'c']);
542-
expect(complete).to.be.false;
543-
expect(error).to.equal('boom');
544-
545-
expect(output).to.deep.equal([1, 2, 3, 4, 5]);
546-
expect(outputComplete).to.be.true;
547-
});
548-
549450
it('should be an Observer which can be given to Observable.subscribe', (done) => {
550451
const source = of(1, 2, 3, 4, 5);
551452
const subject = new Subject<number>();
@@ -781,30 +682,3 @@ describe('Subject', () => {
781682
expect(results).to.deep.equal([1, 1, 2, 2, 'complete']);
782683
});
783684
});
784-
785-
describe('AnonymousSubject', () => {
786-
it('should be exposed', () => {
787-
expect(AnonymousSubject).to.be.a('function');
788-
});
789-
790-
it('should not be eager', () => {
791-
let subscribed = false;
792-
793-
const subject = Subject.create(
794-
null,
795-
new Observable((observer: Observer<any>) => {
796-
subscribed = true;
797-
const subscription = of('x').subscribe(observer);
798-
return () => {
799-
subscription.unsubscribe();
800-
};
801-
})
802-
);
803-
804-
const observable = subject.asObservable();
805-
expect(subscribed).to.be.false;
806-
807-
observable.subscribe();
808-
expect(subscribed).to.be.true;
809-
});
810-
});

packages/rxjs/src/internal/Subject.ts

-37
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ export class Subject<T> extends Observable<T> implements SubscriptionLike {
4040
/** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
4141
thrownError: any = null;
4242

43-
/**
44-
* Creates a "subject" by basically gluing an observer to an observable.
45-
*
46-
* @deprecated Recommended you do not use. Will be removed at some point in the future. Plans for replacement still under discussion.
47-
*/
48-
static create: (...args: any[]) => any = <T>(destination: Observer<T>, source: Observable<T>): AnonymousSubject<T> => {
49-
return new AnonymousSubject<T>(destination, source);
50-
};
51-
5243
constructor() {
5344
// NOTE: This must be here to obscure Observable's constructor.
5445
super();
@@ -146,31 +137,3 @@ export class Subject<T> extends Observable<T> implements SubscriptionLike {
146137
return new Observable((subscriber) => this.subscribe(subscriber));
147138
}
148139
}
149-
150-
export class AnonymousSubject<T> extends Subject<T> {
151-
constructor(
152-
/** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
153-
public destination?: Observer<T>,
154-
/** @internal */
155-
protected _source?: Observable<T>
156-
) {
157-
super();
158-
}
159-
160-
next(value: T) {
161-
this.destination?.next?.(value);
162-
}
163-
164-
error(err: any) {
165-
this.destination?.error?.(err);
166-
}
167-
168-
complete() {
169-
this.destination?.complete?.();
170-
}
171-
172-
/** @internal */
173 4BA6 -
protected _subscribe(subscriber: Subscriber<T>): Subscription {
174-
return this._source?.subscribe(subscriber) ?? Subscription.EMPTY;
175-
}
176-
}

0 commit comments

Comments
 (0)
0