Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11,827 changes: 5,709 additions & 6,118 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
"trailingComma": "all"
},
"devDependencies": {
"@babel/preset-env": "^7.22.7",
"@babel/preset-typescript": "^7.22.5",
"@testing-library/react": "^14.0.0",
"@types/node": "^20.4.7",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@vitest/coverage-v8": "^0.33.0",
"esbuild": "^0.18.11",
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@testing-library/react": "^16.1.0",
"@types/node": "^22.10.5",
"@types/react": "^19.0.4",
"@types/react-dom": "^19.0.2",
"@vitest/coverage-v8": "^2.1.8",
"esbuild": "^0.24.2",
"expose-gc": "^1.0.0",
"husky": ">=8.0.3",
"jest-environment-jsdom": "^29.6.1",
"jsdom": "^22.1.0",
"lint-staged": ">=13.2.3",
"prettier": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^26.0.0",
"lint-staged": "^15.3.0",
"prettier": "^3.4.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-test-renderer": "^19.0.0",
"rxjs": "^7.8.1",
"tslib": "^2.6.0",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
"tslib": "^2.8.1",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,md}": "prettier --write"
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/Subscribe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export const Subscribe: React.FC<{
source$?: Observable<any>
fallback?: NonNullable<ReactNode> | null
}> = ({ source$, children, fallback }) => {
const subscriptionRef = useRef<{
s: Subscription
u: (source: StateObservable<any>) => void
}>()
const subscriptionRef = useRef<
| {
s: Subscription
u: (source: StateObservable<any>) => void
}
| undefined
>(undefined)

if (!subscriptionRef.current) {
const s = new Subscription()
Expand Down
77 changes: 51 additions & 26 deletions packages/core/src/bind/connectFactoryObservable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ describe("connectFactoryObservable", () => {

render(<TestSuspense />)

expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
})

await wait(110)

expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})
})

it("synchronously mounts the emitted value if the observable emits synchronously", () => {
Expand All @@ -110,8 +114,10 @@ describe("connectFactoryObservable", () => {

render(<TestSuspense />)

expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})
})

it("doesn't mount the fallback element if the subscription is already active", () => {
Expand All @@ -133,8 +139,10 @@ describe("connectFactoryObservable", () => {
source$.next(1)
render(<TestSuspense />)

expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})
subscription.unsubscribe()
})

Expand Down Expand Up @@ -246,38 +254,50 @@ describe("connectFactoryObservable", () => {

getDelayedNumber$(0).subscribe()
render(<TestSuspense />)
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
})
await componentAct(async () => {
await getDelayedNumber$(0).pipe(first()).toPromise()
await wait(0)
})
expect(screen.queryByText("Result 0")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 0")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})

componentAct(() => {
getDelayedNumber$(1).subscribe()
fireEvent.click(screen.getByText(/increase/i))
})
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
})
await componentAct(async () => {
await wait(60)
})
expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 1")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})

componentAct(() => {
getDelayedNumber$(2).subscribe()
fireEvent.click(screen.getByText(/increase/i))
})
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result")).toBeNull()
expect(screen.queryByText("Waiting")).not.toBeNull()
})
await componentAct(async () => {
await wait(60)
})
expect(screen.queryByText("Result 2")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Result 2")).not.toBeNull()
expect(screen.queryByText("Waiting")).toBeNull()
})
})

it("shares the source subscription until the refCount has stayed at zero for the grace-period", async () => {
Expand Down Expand Up @@ -439,17 +459,20 @@ describe("connectFactoryObservable", () => {
<ErrorComponent />
</TestErrorBoundary>,
)

expect(screen.queryByText("ALL GOOD")).toBeNull()
expect(screen.queryByText("Loading...")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("ALL GOOD")).toBeNull()
expect(screen.queryByText("Loading...")).not.toBeNull()
})

await componentAct(async () => {
normal$.next("ALL GOOD")
await wait(50)
})

expect(screen.queryByText("ALL GOOD")).not.toBeNull()
expect(screen.queryByText("Loading...")).toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("ALL GOOD")).not.toBeNull()
expect(screen.queryByText("Loading...")).toBeNull()
})
expect(errorCallback).not.toHaveBeenCalled()

componentAct(() => {
Expand Down Expand Up @@ -665,7 +688,9 @@ describe("connectFactoryObservable", () => {

render(<Container />)

expect(screen.queryByText("Waiting")).not.toBeNull()
vi.waitFor(() => {
expect(screen.queryByText("Waiting")).not.toBeNull()
})
componentAct(() => {
ticks$.next()
})
Expand Down
Loading
Loading