mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-27 18:30:35 +01:00
fix(Form): memory leak (#1185)
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { provide, ref, type PropType, defineComponent } from 'vue'
|
import { provide, ref, type PropType, defineComponent, onUnmounted, onMounted } from 'vue'
|
||||||
import { useEventBus } from '@vueuse/core'
|
import { useEventBus } from '@vueuse/core'
|
||||||
import type { ZodSchema } from 'zod'
|
import type { ZodSchema } from 'zod'
|
||||||
import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
|
import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
|
||||||
@@ -51,10 +51,16 @@ export default defineComponent({
|
|||||||
setup (props, { expose, emit }) {
|
setup (props, { expose, emit }) {
|
||||||
const bus = useEventBus<FormEvent>(`form-${uid()}`)
|
const bus = useEventBus<FormEvent>(`form-${uid()}`)
|
||||||
|
|
||||||
bus.on(async (event) => {
|
onMounted(() => {
|
||||||
if (event.type !== 'submit' && props.validateOn?.includes(event.type)) {
|
bus.on(async (event) => {
|
||||||
await validate(event.path, { silent: true })
|
if (event.type !== 'submit' && props.validateOn?.includes(event.type)) {
|
||||||
}
|
await validate(event.path, { silent: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
bus.reset()
|
||||||
})
|
})
|
||||||
|
|
||||||
const errors = ref<FormError[]>([])
|
const errors = ref<FormError[]>([])
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
let _id = 0
|
let _id = 0
|
||||||
|
|
||||||
export function uid () {
|
export function uid () {
|
||||||
return `nuid-${_id++}`
|
_id = (_id + 1) % Number.MAX_SAFE_INTEGER
|
||||||
|
return `nuid-${_id}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user