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

feat: remove deprecated observable symbol export (#4466) #7361

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/rxjs/spec/helpers/interop-helper-spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { expect } from 'chai';
import { Observable, of, Subscriber } from 'rxjs';
import { observable as symbolObservable } from 'rxjs/internal/symbol/observable';
import { asInteropObservable, asInteropSubscriber } from './interop-helper';

describe('interop helper', () => {
it('should simulate interop observables', () => {
const observable: any = asInteropObservable(of(42));
expect(observable).to.not.be.instanceOf(Observable);
expect(observable[symbolObservable]).to.be.a('function');
expect(observable[Symbol.observable ?? '@@observable']).to.be.a('function');
});

it('should simulate interop subscribers', () => {
Expand Down
57 changes: 28 additions & 29 deletions packages/rxjs/spec/helpers/test-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { of, asyncScheduler, Observable, scheduled, ObservableInput } from 'rxjs';
import { observable } from 'rxjs/internal/symbol/observable';
import { iterator } from 'rxjs/internal/symbol/iterator';

if (process && process.on) {
Expand All @@ -9,7 +8,7 @@ if (process && process.on) {
* it handles the rejected promise where it does not notice
* that the test failed.
*/
process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
console.error(err);
process.exit(1);
});
Expand All @@ -18,45 +17,45 @@ if (process && process.on) {
export function lowerCaseO<T>(...args: Array<any>): Observable<T> {
const o: any = {
subscribe(observer: any) {
args.forEach(v => observer.next(v));
args.forEach((v) => observer.next(v));
observer.complete();
return {
unsubscribe() { /* do nothing */ }
unsubscribe() {
/* do nothing */
},
};
}
},
};

o[observable] = function (this: any) {
o[Symbol.observable ?? '@@observable'] = function (this: any) {
return this;
};

return <any>o;
}

export const createObservableInputs = <T>(value: T) => of(
of(value),
scheduled([value], asyncScheduler),
[value],
Promise.resolve(value),
{
[iterator]: () => {
const iteratorResults = [
{ value, done: false },
{ done: true }
];
return {
next: () => {
return iteratorResults.shift();
}
};
}
} as any as Iterable<T>,
{
[observable]: () => of(value)
} as any
) as Observable<ObservableInput<T>>;
export const createObservableInputs = <T>(value: T) =>
of(
of(value),
scheduled([value], asyncScheduler),
[value],
Promise.resolve(value),
{
[iterator]: () => {
const iteratorResults = [{ value, done: false }, { done: true }];
return {
next: () => {
return iteratorResults.shift();
},
};
},
} as any as Iterable<T>,
{
[Symbol.observable ?? '@@observable']: () => of(value),
} as any
) as Observable<ObservableInput<T>>;

/**
* Used to signify no subscriptions took place to `expectSubscriptions` assertions.
*/
export const NO_SUBS: string[] = [];
export const NO_SUBS: string[] = [];
8 changes: 4 additions & 4 deletions packages/rxjs/spec/observables/from-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @prettier */
import { expect } from 'chai';
import { TestScheduler } from 'rxjs/testing';
import { asyncScheduler, of, from, Observer, observable, Subject, noop, Subscription } from 'rxjs';
import { of, from, Observer, Subject, noop, Subscription } from 'rxjs';
import { first, concatMap, delay, take, tap } from 'rxjs/operators';
import { ReadableStream } from 'web-streams-polyfill';
import { observableMatcher } from '../helpers/observableMatcher';
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('from', () => {
});

const fakervable = <T>(...values: T[]) => ({
[observable]: () => ({
[Symbol.observable ?? '@@observable']: () => ({
subscribe: (observer: Observer<T>) => {
for (const value of values) {
observer.next(value);
Expand All @@ -178,7 +178,7 @@ describe('from', () => {

const fakeArrayObservable = <T>(...values: T[]) => {
let arr: any = ['bad array!'];
arr[observable] = () => {
arr[Symbol.observable ?? '@@observable'] = () => {
return {
subscribe: (observer: Observer<T>) => {
for (const value of values) {
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('from', () => {
it(`should accept a function that implements [Symbol.observable]`, (done) => {
const subject = new Subject<any>();
const handler: any = (arg: any) => subject.next(arg);
handler[observable] = () => subject;
handler[Symbol.observable ?? '@@observable'] = () => subject;
let nextInvoked = false;

from(handler as any)
Expand Down
1 change: 0 additions & 1 deletion packages/rxjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
export { Observable } from './internal/Observable.js';
export { GroupedObservable } from './internal/operators/groupBy.js';
export { Operator } from './internal/Operator.js';
export { observable } from './internal/symbol/observable.js';
export { animationFrames } from './internal/observable/dom/animationFrames.js';

/* Subjects */
Expand Down
3 changes: 1 addition & 2 deletions packages/rxjs/src/internal/Observable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Subscriber } from './Subscriber.js';
import { Subscription } from './Subscription.js';
import { TeardownLogic, UnaryFunction, Subscribable, Observer, OperatorFunction } from './types.js';
import { observable as Symbol_observable } from './symbol/observable.js';
import { pipeFromArray } from './util/pipe.js';
/**
* A representation of any set of values over any amount of time. This is the most basic building block
Expand Down Expand Up @@ -240,7 +239,7 @@ export class Observable<T> implements Subscribable<T> {
* An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable
* @return This instance of the observable.
*/
[Symbol_observable]() {
[Symbol.observable ?? '@@observable']() {
return this;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/rxjs/src/internal/observable/from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { isReadableStreamLike, readableStreamLikeToAsyncGenerator } from '../uti
import { Subscriber } from '../Subscriber.js';
import { isFunction } from '../util/isFunction.js';
import { reportUnhandledError } from '../util/reportUnhandledError.js';
import { observable as Symbol_observable } from '../symbol/observable.js';

/**
* Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.
Expand Down Expand Up @@ -117,7 +116,7 @@ export function from<T>(input: ObservableInput<T>): Observable<T> {
*/
function fromInteropObservable<T>(obj: any) {
return new Observable((subscriber: Subscriber<T>) => {
const obs = obj[Symbol_observable]();
const obs = obj[Symbol.observable ?? '@@observable']();
if (isFunction(obs.subscribe)) {
return obs.subscribe(subscriber);
}
Expand Down
7 changes: 0 additions & 7 deletions packages/rxjs/src/internal/symbol/observable.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/rxjs/src/internal/util/isInteropObservable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { InteropObservable } from '../types.js';
import { observable as Symbol_observable } from '../symbol/observable.js';
import { isFunction } from './isFunction.js';

/** Identifies an input as being Observable (but not necessary an Rx Observable) */
export function isInteropObservable(input: any): input is InteropObservable<any> {
return isFunction(input[Symbol_observable]);
return isFunction(input[Symbol.observable ?? '@@observable']);
}
Loading