ef00732685
- Made the use of `const` and `let` consistent - import required functions and types from 'react' instead of using the `React.` namespace. - Added `Expand` type, which can expand complex types to their "final" result. - Ensured that we use `as const` for DEFAULT_XXX_TAG where we used a string. So that we have the type of `div` instead of `string` for example. - Used `interface` over `type` where possible. I'm personally more of a `type` fan. But the TypeScript recommends `interfaces` where possible because they are faster, yield better error messages and so on.
21 lines
383 B
TypeScript
21 lines
383 B
TypeScript
import { disposables } from '../utils/disposables'
|
|
|
|
export function reportChanges<TType>(key: () => TType, onChange: (value: TType) => void) {
|
|
let d = disposables()
|
|
|
|
let previous: TType
|
|
|
|
function track() {
|
|
let next = key()
|
|
if (previous !== next) {
|
|
previous = next
|
|
onChange(next)
|
|
}
|
|
d.requestAnimationFrame(track)
|
|
}
|
|
|
|
track()
|
|
|
|
return d.dispose
|
|
}
|