-
Notifications
You must be signed in to change notification settings - Fork 42
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: make Observable class internal #690
Labels
enhancement
New feature or request
Comments
#687 introduces an util to get AsyncIterable from Observable. |
This was
linked to
pull requests
Jul 11, 2024
I think Define a type /**
* NativeSubject is native version of rx's Subject, which can be used in async generator.
*
* @public
*/
export type NativeSubject<T> = AsyncIterable<T> & AsyncIterator<T, void, T>;
/**
* convert a rx's Subject to a NativeSubject.
*
* @param subject$ - the rx's Subject to convert
* @returns a NativeSubject
*
* @public
*/
export const subjectToNativeSubject = <T>(subject$: Subject<T>): NativeSubject<T> => ({
...observableToAsyncIterable(subject$),
next: (value: T) => {
subject$.next(value);
return Promise.resolve({ value, done: false });
},
return: () => {
subject$.complete();
return Promise.resolve({ value: undefined, done: true });
},
throw: (e: any) => {
subject$.error(e);
return Promise.reject(e);
},
});
/**
* convert a NativeSubject to a rx's Subject.
*
* @param source - the NativeSubject to convert
* @returns a rx's Subject
*
* @public
*/
export const nativeSubjectToSubject = <T>(source: NativeSubject<T>): Subject<T> => {
const subject$ = new Subject<T>();
subject$.subscribe({
next(v) {
source.next(v);
},
complete() {
source.return?.();
},
error(e) {
source.throw?.(e);
},
});
return subject$;
}; |
#693 implemented |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the feature
Check all libraries's exporting API:
Observable<T>
and replace them withAsyncIterable<T>
Subject<T>
and replace them withNativeSubject<T> = AsyncIterable<T> | AsyncIterator<T, void, T>
.ObservableInput<T>
and replace them withAsyncIterable<T> | PromiseLike<T> | ArrayLike<T> | Iterable<T>
Hint: All
Observable<T>
can be transformed toAsyncIterable<T>
, and back toObservable<T>
.Why do you need this feature?
It might cause compatibility issues.
Confusing when someone is new to development.
Additional context
Observable of
rxjs
is useful for defining a stream interface.But, the issue is that when we export an interface with Observable, it will bind the version of rxjs. (because Observable is a class rather than an interface)
We met a compiling error: Observable cannot be assigned to another Observable from a different version of
rxjs
.The solutions are:
To introduce the short rule: Never export a class type
In JavaScript & node modules cache & npm:
So, exporting a class type might cause compatibility issues.
The text was updated successfully, but these errors were encountered: