Skip to content

Commit

Permalink
[v2] export Snapshot type (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Feb 9, 2024
1 parent 4162033 commit fae36c9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
isChanged,
} from 'proxy-compare'
import { snapshot, subscribe } from './vanilla.ts'
import type { INTERNAL_Snapshot as Snapshot } from './vanilla.ts'
import type { Snapshot } from './vanilla.ts'

const useAffectedDebugValue = (
state: object,
Expand Down
8 changes: 1 addition & 7 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ type SnapshotIgnore =
| AnyFunction
| Primitive

type Snapshot<T> = T extends { $$valtioSnapshot: infer S }
export type Snapshot<T> = T extends { $$valtioSnapshot: infer S }
? S
: T extends SnapshotIgnore
? T
: T extends object
? { readonly [K in keyof T]: Snapshot<T[K]> }
: T

/**
* This is not a public API.
* It can be changed without any notice.
*/
export type INTERNAL_Snapshot<T> = Snapshot<T>

type CreateSnapshot = <T extends object>(target: T, version: number) => T

type RemoveListener = () => void
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshot.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createProxy, getUntracked } from 'proxy-compare'
import { TypeEqual, expectType } from 'ts-expect'
import { describe, expect, it } from 'vitest'
import { INTERNAL_Snapshot as Snapshot, proxy, snapshot } from 'valtio'
import { Snapshot, proxy, snapshot } from 'valtio'

it('should return correct snapshots without subscribe', async () => {
const child = proxy({ count: 0 })
Expand Down

0 comments on commit fae36c9

Please sign in to comment.