Switch to vite and preact

This commit is contained in:
Misode
2021-06-23 20:44:28 +02:00
parent e551b7ef75
commit 09c851914f
89 changed files with 6398 additions and 15531 deletions

20
src/app/hooks/useModel.ts Normal file
View File

@@ -0,0 +1,20 @@
import type { DataModel } from '@mcschema/core'
import { useEffect } from 'preact/hooks'
export function useModel(model: DataModel | undefined | null, invalidated: (model: DataModel) => unknown) {
const listener = {
invalidated() {
if (model) {
invalidated(model)
}
},
}
useEffect(() => {
model?.addListener(listener)
listener.invalidated()
return () => {
model?.removeListener(listener)
}
}, [model])
}