From 68aa53a47308279ea9dc8d65397ab2a7013bd118 Mon Sep 17 00:00:00 2001 From: daishi Date: Sun, 18 Aug 2024 16:36:04 +0900 Subject: [PATCH] breaking(vanilla): do not handle promises --- src/vanilla.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/vanilla.ts b/src/vanilla.ts index 2a982c3d..9301ed9b 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -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 @@ -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 = ( target: T, @@ -130,25 +129,9 @@ const createHandlerDefault = ( 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