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

Update rxjs peer dependency to include rxjs 7.x #103

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions .changeset/popular-chefs-laugh.md
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
2 changes: 1 addition & 1 deletion packages/examples/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"react-transform-catch-errors": "^1.0.2",
"react-transform-hmr": "^1.0.4",
"redbox-react": "^1.3.0",
"rxjs": "6.3.3",
"rxjs": "^7.8.1",
"style-loader": "^1.0.0",
"todomvc-app-css": "^2.0.6",
"ts-loader": "8.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/todomvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react-transform-catch-errors": "^1.0.2",
"react-transform-hmr": "^1.0.4",
"redbox-react": "^1.3.0",
"rxjs": "6.3.3",
"rxjs": "^7.8.1",
"todomvc-app-css": "^2.0.6",
"ts-loader": "8.2.0",
"typescript": "^4.7.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/focal-atom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
"@types/jest": "^24.0.20",
"@types/node": "^18.0.0",
"jest": "^28.1.1",
"rxjs": "6.3.3",
"rxjs": "^7.8.1",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
},
"peerDependencies": {
"rxjs": ">= 6.3.3 < 7.0.0-0"
"rxjs": ">= 6.3.3 < 8.0.0-0"
}
}
41 changes: 34 additions & 7 deletions packages/focal-atom/src/atom/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -371,7 +380,13 @@ class LensedAtom<TSource, TDest> extends AbstractAtom<TDest> {
private _refCount = 0

// Rx method overrides
_subscribe(subscriber: Subscriber<TDest>) {
Copy link
Contributor Author

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

_subscribe method is no longer public and is now marked @internal.

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))
}
Expand All @@ -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>>])))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make TS happy


return sub
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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))
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions packages/focal-atom/test/atom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

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

toPromise method now correctly returns Promise<T | undefined> instead of Promise<T>. This is a correction without a runtime change, because if the observable does not emit a value before completion, the promise will resolve with undefined.

})

test('emits atom once', async () => {
Expand All @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/focal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"jest-environment-jsdom": "^28.1.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"rxjs": "6.3.3",
"rxjs": "^7.8.1",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
},
Expand All @@ -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"
}
}
7 changes: 5 additions & 2 deletions packages/focal/src/react/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"react-transform-catch-errors": "^1.0.2",
"react-transform-hmr": "^1.0.4",
"redbox-react": "^1.3.0",
"rxjs": "6.3.3",
"rxjs": "^7.8.1",
"todomvc-app-css": "^2.0.6",
"ts-loader": "8.2.0",
"typescript": "^4.7.4",
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5115,12 +5115,12 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

rxjs@6.3.3:
version "6.3.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz#3c6a7fa420e844a81390fb1158a9ec614f4bad55"
integrity sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==
rxjs@^7.8.1:
version "7.8.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543"
integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==
dependencies:
tslib "^1.9.0"
tslib "^2.1.0"

safe-array-concat@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -5779,11 +5779,16 @@ ts-loader@8.2.0:
micromatch "^4.0.0"
semver "^7.3.4"

tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
tslib@^1.8.0, tslib@^1.8.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.1.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

tslint@5.20.0:
version "5.20.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.0.tgz#fac93bfa79568a5a24e7be9cdde5e02b02d00ec1"
Expand Down