diff --git a/.changeset/popular-chefs-laugh.md b/.changeset/popular-chefs-laugh.md new file mode 100644 index 0000000..b40b782 --- /dev/null +++ b/.changeset/popular-chefs-laugh.md @@ -0,0 +1,6 @@ +--- +"@grammarly/focal-atom": minor +"@grammarly/focal": minor +--- + +Update peer dependency to include rxjs versions up to 7.x diff --git a/packages/focal-atom/package.json b/packages/focal-atom/package.json index bad0300..956c320 100644 --- a/packages/focal-atom/package.json +++ b/packages/focal-atom/package.json @@ -94,6 +94,6 @@ "typescript": "^4.7.4" }, "peerDependencies": { - "rxjs": ">= 6.3.3 < 7.0.0-0" + "rxjs": ">= 6.3.3 < 8.0.0-0" } } diff --git a/packages/focal-atom/src/atom/base.ts b/packages/focal-atom/src/atom/base.ts index 1b64ae2..145e6fa 100644 --- a/packages/focal-atom/src/atom/base.ts +++ b/packages/focal-atom/src/atom/base.ts @@ -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 = readonly [ + observerOrNext?: Partial> | ((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 extends AbstractAtom { private _refCount = 0 // Rx method overrides - _subscribe(subscriber: Subscriber) { + subscribe(observerOrNext?: Partial> | ((value: TDest) => void)): Subscription + subscribe( + next?: ((value: TDest) => void) | null, + error?: ((error: any) => void) | null, + complete?: (() => void) | null + ): Subscription + subscribe(...args: SubscribeParameters) { if (!this._subscription) { this._subscription = this._source.subscribe(x => this._onSourceValue(x)) } @@ -383,7 +398,7 @@ class LensedAtom extends AbstractAtom { this._subscription = null } }) - sub.add(super._subscribe(subscriber)) + sub.add(super.subscribe(...(args as [Observer]))) return sub } @@ -440,7 +455,13 @@ class AtomViewImpl extends AbstractReadOnlyAtom { private _refCount = 0 // Rx method overrides - _subscribe(subscriber: Subscriber) { + subscribe(observerOrNext?: Partial> | ((value: TDest) => void)): Subscription + subscribe( + next?: ((value: TDest) => void) | null, + error?: ((error: any) => void) | null, + complete?: (() => void) | null + ): Subscription + subscribe(...args: SubscribeParameters) { if (!this._subscription) { this._subscription = this._source.subscribe(x => this._onSourceValue(x)) } @@ -452,7 +473,7 @@ class AtomViewImpl extends AbstractReadOnlyAtom { this._subscription = null } }) - sub.add(super._subscribe(subscriber)) + sub.add(super.subscribe(...(args as [Observer]))) return sub } @@ -510,7 +531,13 @@ export class CombinedAtomViewImpl extends AbstractReadOnlyAtom private _refCount = 0 // Rx method overrides - _subscribe(subscriber: Subscriber) { + subscribe(observerOrNext?: Partial> | ((value: TResult) => void)): Subscription + subscribe( + next?: ((value: TResult) => void) | null, + error?: ((error: any) => void) | null, + complete?: (() => void) | null + ): Subscription + subscribe(...args: SubscribeParameters) { if (!this._subscription) { this._subscription = combineLatest(this._sources) .subscribe(xs => this._onSourceValues(xs)) @@ -523,7 +550,7 @@ export class CombinedAtomViewImpl extends AbstractReadOnlyAtom this._subscription = null } }) - sub.add(super._subscribe(subscriber)) + sub.add(super.subscribe(...(args as [Observer]))) return sub } diff --git a/packages/focal-atom/test/atom.test.ts b/packages/focal-atom/test/atom.test.ts index 544f6a3..60722a4 100644 --- a/packages/focal-atom/test/atom.test.ts +++ b/packages/focal-atom/test/atom.test.ts @@ -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) }) 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', () => { diff --git a/packages/focal/package.json b/packages/focal/package.json index 26e3c78..8727c7a 100644 --- a/packages/focal/package.json +++ b/packages/focal/package.json @@ -105,6 +105,6 @@ "@types/react-dom": ">= 18.0.0 < 19.0.0-0", "react": ">= 18.0.0 < 19.0.0-0", "react-dom": ">= 18.0.0 < 19.0.0-0", - "rxjs": ">= 6.3.3 < 7.0.0-0" + "rxjs": ">= 6.3.3 < 8.0.0-0" } } diff --git a/packages/focal/src/react/react.ts b/packages/focal/src/react/react.ts index 2b2878e..b94bc10 100644 --- a/packages/focal/src/react/react.ts +++ b/packages/focal/src/react/react.ts @@ -606,9 +606,12 @@ export function classes( filterClassNames(cs || []).map(x => // @TODO optimize: unnecessary Observable.of // can we actually already just remove this? - !(x instanceof Observable) ? of(x) : x + + // we check if x is a string because after `filterClassNames` + // it can be only a string as non-observable value; otherwise it is an `ObservableInput` + typeof x === 'string' ? of(x) : x ), - (...cs: ClassNameLike[]) => { + (...cs) => { const filtered = filterClassNames(cs || []) return filtered.length > 0