-
Notifications
You must be signed in to change notification settings - Fork 34
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
Update rxjs peer dependency to include rxjs 7.x #103
Changes from 4 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@grammarly/focal-atom": minor | ||
"@grammarly/focal": minor | ||
--- | ||
|
||
Update peer dependency to include rxjs versions up to 7.x |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,16 @@ import { Lens, Prism, PropExpr } from './../lens' | |
import { Option } from './../utils' | ||
import { structEq } from './../equals' | ||
|
||
import { Observable, Subscriber, Subscription, BehaviorSubject, combineLatest } from 'rxjs' | ||
import { Observable, Subscription, BehaviorSubject, combineLatest, Observer } from 'rxjs' | ||
|
||
/** Parameters of the implementation of the overloaded `Subscribable.subscribe` method. */ | ||
type SubscribeParameters<T> = readonly [ | ||
observerOrNext?: Partial<Observer<T>> | ((value: T) => void), | ||
] | readonly [ | ||
next?: ((value: T) => void) | null, | ||
error?: ((error: any) => void) | null, | ||
complete?: (() => void) | null | ||
] | ||
|
||
/** | ||
* Read-only atom. | ||
|
@@ -371,7 +380,13 @@ class LensedAtom<TSource, TDest> extends AbstractAtom<TDest> { | |
private _refCount = 0 | ||
|
||
// Rx method overrides | ||
_subscribe(subscriber: Subscriber<TDest>) { | ||
subscribe(observerOrNext?: Partial<Observer<TDest>> | ((value: TDest) => void)): Subscription | ||
subscribe( | ||
next?: ((value: TDest) => void) | null, | ||
error?: ((error: any) => void) | null, | ||
complete?: (() => void) | null | ||
): Subscription | ||
subscribe(...args: SubscribeParameters<TDest>) { | ||
if (!this._subscription) { | ||
this._subscription = this._source.subscribe(x => this._onSourceValue(x)) | ||
} | ||
|
@@ -383,7 +398,7 @@ class LensedAtom<TSource, TDest> extends AbstractAtom<TDest> { | |
this._subscription = null | ||
} | ||
}) | ||
sub.add(super._subscribe(subscriber)) | ||
sub.add(super.subscribe(...(args as [Partial<Observer<TDest>>]))) | ||
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. to make TS happy |
||
|
||
return sub | ||
} | ||
|
@@ -440,7 +455,13 @@ class AtomViewImpl<TSource, TDest> extends AbstractReadOnlyAtom<TDest> { | |
private _refCount = 0 | ||
|
||
// Rx method overrides | ||
_subscribe(subscriber: Subscriber<TDest>) { | ||
subscribe(observerOrNext?: Partial<Observer<TDest>> | ((value: TDest) => void)): Subscription | ||
subscribe( | ||
next?: ((value: TDest) => void) | null, | ||
error?: ((error: any) => void) | null, | ||
complete?: (() => void) | null | ||
): Subscription | ||
subscribe(...args: SubscribeParameters<TDest>) { | ||
if (!this._subscription) { | ||
this._subscription = this._source.subscribe(x => this._onSourceValue(x)) | ||
} | ||
|
@@ -452,7 +473,7 @@ class AtomViewImpl<TSource, TDest> extends AbstractReadOnlyAtom<TDest> { | |
this._subscription = null | ||
} | ||
}) | ||
sub.add(super._subscribe(subscriber)) | ||
sub.add(super.subscribe(...(args as [Partial<Observer<TDest>>]))) | ||
|
||
return sub | ||
} | ||
|
@@ -510,7 +531,13 @@ export class CombinedAtomViewImpl<TResult> extends AbstractReadOnlyAtom<TResult> | |
private _refCount = 0 | ||
|
||
// Rx method overrides | ||
_subscribe(subscriber: Subscriber<TResult>) { | ||
subscribe(observerOrNext?: Partial<Observer<TResult>> | ((value: TResult) => void)): Subscription | ||
subscribe( | ||
next?: ((value: TResult) => void) | null, | ||
error?: ((error: any) => void) | null, | ||
complete?: (() => void) | null | ||
): Subscription | ||
subscribe(...args: SubscribeParameters<TResult>) { | ||
if (!this._subscription) { | ||
this._subscription = combineLatest(this._sources) | ||
.subscribe(xs => this._onSourceValues(xs)) | ||
|
@@ -523,7 +550,7 @@ export class CombinedAtomViewImpl<TResult> extends AbstractReadOnlyAtom<TResult> | |
this._subscription = null | ||
} | ||
}) | ||
sub.add(super._subscribe(subscriber)) | ||
sub.add(super.subscribe(...(args as [Partial<Observer<TResult>>]))) | ||
|
||
return sub | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -744,7 +744,7 @@ describe('atom', () => { | |
describe('fromObservable', () => { | ||
test('emits atom', async () => { | ||
const a = await Atom.fromObservable(from([1])).pipe(take(1)).toPromise() | ||
expect(a.get()).toEqual(1) | ||
expect(a?.get()).toEqual(1) | ||
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.
|
||
}) | ||
|
||
test('emits atom once', async () => { | ||
|
@@ -755,7 +755,7 @@ describe('atom', () => { | |
from(['hello']) | ||
).pipe(take(2), toArray()).toPromise() | ||
|
||
expect(a[1]).toEqual('hello') | ||
expect(a?.[1]).toEqual('hello') | ||
}) | ||
|
||
test('does not subscribe to source immediately', () => { | ||
|
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.
rxjs@7
https://rxjs.dev/6-to-7-change-summary#observable