* 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
23 lines
683 B
TypeScript
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)
|
|
}
|