Skip to content

Commit

Permalink
breaking(vanilla): do not handle promises
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Aug 18, 2024
1 parent c255446 commit 68aa53a
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ type Path = (string | symbol)[]
type Op =
| [op: 'set', path: Path, value: unknown, prevValue: unknown]
| [op: 'delete', path: Path, prevValue: unknown]
| [op: 'resolve', path: Path, value: unknown]
| [op: 'reject', path: Path, error: unknown]
type Listener = (op: Op, nextVersion: number) => void

type Primitive = string | number | boolean | null | undefined | symbol | bigint
Expand Down Expand Up @@ -56,7 +54,8 @@ const canProxyDefault = (x: unknown) =>
!(x instanceof Date) &&
!(x instanceof String) &&
!(x instanceof RegExp) &&
!(x instanceof ArrayBuffer)
!(x instanceof ArrayBuffer) &&
!(x instanceof Promise)

const createSnapshotDefault = <T extends object>(
target: T,
Expand Down Expand Up @@ -130,25 +129,9 @@ const createHandlerDefault = <T extends object>(
if (isObject(value)) {
value = getUntracked(value) || value
}
let nextValue = value
if (value instanceof Promise) {
value
.then((v) => {
;(value as any).status = 'fulfilled'
;(value as any).value = v
notifyUpdate(['resolve', [prop], v])
})
.catch((e) => {
;(value as any).status = 'rejected'
;(value as any).reason = e
notifyUpdate(['reject', [prop], e])
})
} else {
if (!proxyStateMap.has(value) && canProxy(value)) {
nextValue = proxy(value)
}
addPropListener(prop, nextValue)
}
const nextValue =
!proxyStateMap.has(value) && canProxy(value) ? proxy(value) : value
addPropListener(prop, nextValue)
Reflect.set(target, prop, nextValue, receiver)
notifyUpdate(['set', [prop], value, prevValue])
return true
Expand Down

0 comments on commit 68aa53a

Please sign in to comment.