pages235/renderer/viewer/lib/utils/proxy.ts
Vitaly 65af9a73c2
feat: rework hand! enable by default, fix bow anim (#261)
* refactor swing animation to controller

* idle animator!!!!

* implelment state switch transition

* a huge fix for UI server edit!

* adjust ui scaling so main menu elements clip less

* view bobbing, new config name, ws:

* EXTREMELY important fixes to entities rendering

* a lot of fixes, add dns resolve fallback

* improve f3 E, fix modal not found edge case

* set correctly target for old browsers, should fix ios 14 crash

* unecessary big refactor, to fix ts err

* fix isWysiwyg check

* fix entities rendering count
2025-02-15 05:14:36 +03:00

23 lines
683 B
TypeScript

import { subscribeKey } from 'valtio/utils'
// eslint-disable-next-line max-params
export function watchProperty<T extends Record<string, any>, K> (asyncGetter: (value: T[keyof T]) => Promise<K>, valtioProxy: T, key: keyof T, readySetter: (res: K) => void, cleanup?: (res: K) => void) {
let i = 0
let lastRes: K | undefined
const request = async () => {
const req = ++i
const res = await asyncGetter(valtioProxy[key])
if (req === i) {
if (lastRes) {
cleanup?.(lastRes)
}
readySetter(res)
lastRes = res
} else {
// rejected
cleanup?.(res)
}
}
void request()
return subscribeKey(valtioProxy, key, request)
}