Skip to content

Commit

Permalink
use use
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Nov 10, 2023
1 parent 40636a2 commit 5c98de7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/react.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="react/experimental" />

import { useCallback, useDebugValue, useEffect, useMemo, useRef } from 'react'
import {
affectedToPathList,
Expand Down
4 changes: 3 additions & 1 deletion tests/async.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="react/canary" />

import { StrictMode, Suspense, use } from 'react'

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Module '"react"' has no exported member 'use'.

Check failure on line 3 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.
import { fireEvent, render, waitFor } from '@testing-library/react'
import { it } from 'vitest'
Expand All @@ -8,7 +10,7 @@ const sleep = (ms: number) =>
setTimeout(resolve, ms)
})

const use2 = <T,>(x: T): T => (x instanceof Promise ? use(x) : x)
const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.4.4)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.3.5)

Cannot find name 'Awaited'.

Check failure on line 13 in tests/async.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Cannot find name 'Awaited'.

it('delayed increment', async () => {
const state = proxy<any>({ count: 0 })
Expand Down
8 changes: 6 additions & 2 deletions tests/computed.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { StrictMode, Suspense } from 'react'
/// <reference types="react/canary" />

import { StrictMode, Suspense, use } from 'react'

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Module '"react"' has no exported member 'use'.

Check failure on line 3 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.
import { fireEvent, render } from '@testing-library/react'
import { memoize } from 'proxy-memoize'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { proxy, snapshot, subscribe, useSnapshot } from 'valtio'
import { addComputed, proxyWithComputed, subscribeKey } from 'valtio/utils'

const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.4.4)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.3.5)

Cannot find name 'Awaited'.

Check failure on line 10 in tests/computed.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Cannot find name 'Awaited'.

const consoleWarn = console.warn
beforeEach(() => {
console.warn = vi.fn((message: string) => {
Expand Down Expand Up @@ -217,7 +221,7 @@ describe('DEPRECATED addComputed', () => {
return (
<>
<div>
count: {snap.count}, delayedCount: {snap.delayedCount}
count: {snap.count}, delayedCount: {use2(snap.delayedCount)}
</div>
<button onClick={() => ++state.count}>button</button>
</>
Expand Down
8 changes: 6 additions & 2 deletions tests/derive.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { StrictMode, Suspense, useEffect, useRef } from 'react'
/// <reference types="react/canary" />

import { StrictMode, Suspense, use, useEffect, useRef } from 'react'

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Module '"react"' has no exported member 'use'.

Check failure on line 3 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Module '"../node_modules/@types/react/ts5.0"' has no exported member 'use'.
import { fireEvent, render } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { proxy, snapshot, subscribe, useSnapshot } from 'valtio'
Expand All @@ -11,6 +13,8 @@ const sleep = (ms: number) =>
setTimeout(resolve, ms)
})

const use2 = <T,>(x: T): Awaited<T> => (x instanceof Promise ? use(x) : x)

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.1.5)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.4.4)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.8.3)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.9.7)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.0.5)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.2.3)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (4.3.5)

Cannot find name 'Awaited'.

Check failure on line 16 in tests/derive.test.tsx

View workflow job for this annotation

GitHub Actions / test_matrix (3.7.5)

Cannot find name 'Awaited'.

it('basic derive', async () => {
const computeDouble = vi.fn((x: number) => x * 2)
const state = proxy({
Expand Down Expand Up @@ -168,7 +172,7 @@ it('async derive', async () => {
return (
<>
<div>
count: {snap.count}, delayedCount: {snap.delayedCount}
count: {snap.count}, delayedCount: {use2(snap.delayedCount)}
</div>
<button onClick={() => ++state.count}>button</button>
</>
Expand Down

0 comments on commit 5c98de7

Please sign in to comment.