@mezzanine-ui/react-hook-form
Advanced tools
Comparing version 0.15.3 to 0.15.4
{ | ||
"name": "@mezzanine-ui/react-hook-form", | ||
"version": "0.15.3", | ||
"version": "0.15.4", | ||
"description": "Form with data binding HOC for mezzanine-ui", | ||
@@ -5,0 +5,0 @@ "author": "mezzanine", |
@@ -32,6 +32,8 @@ import { jsx } from 'react/jsx-runtime'; | ||
const onClear = () => { | ||
cancelDebounce$.next(); | ||
setInputValue(''); | ||
clearInput(); | ||
setKey((prev) => prev + 1); | ||
// put clean-up task into macro-task queue. | ||
setTimeout(() => { | ||
clearInput(); | ||
cancelDebounce$.next(); | ||
}); | ||
}; | ||
@@ -42,2 +44,3 @@ const onChange = (e) => { | ||
onClear(); | ||
setKey((prev) => prev + 1); // force refresh view. | ||
} | ||
@@ -57,3 +60,3 @@ else { | ||
if (!watchedDebouncedValue) | ||
onClear(); | ||
setInputValue(''); | ||
} | ||
@@ -63,3 +66,2 @@ else if (typeof watchedDebouncedValue === 'undefined' | ||
setInputValue(''); // reset event | ||
setKey((prev) => prev + 1); // force refresh view | ||
} | ||
@@ -66,0 +68,0 @@ }, [registerName, watchedDebouncedValue]); |
import { useState, useEffect } from 'react'; | ||
import { useWatch } from 'react-hook-form'; | ||
import { fromEvent, Subject } from 'rxjs'; | ||
import { takeUntil, repeatWhen, debounceTime, distinctUntilChanged } from 'rxjs/operators'; | ||
import { repeat, debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators'; | ||
import { isBrowser } from '../utils/type-checker.js'; | ||
@@ -25,3 +25,3 @@ | ||
const subscription = input$ | ||
.pipe(takeUntil(cancel$ || new Subject()), repeatWhen(() => input$), debounceTime(debounceMs !== null && debounceMs !== void 0 ? debounceMs : 500), distinctUntilChanged()) | ||
.pipe(repeat({ delay: () => input$ }), debounceTime(debounceMs !== null && debounceMs !== void 0 ? debounceMs : 500), distinctUntilChanged(), takeUntil(cancel$ || new Subject())) | ||
.subscribe((e) => { | ||
@@ -36,5 +36,3 @@ onChange === null || onChange === void 0 ? void 0 : onChange(e); | ||
useEffect(() => { | ||
if (!value) { | ||
setDebouncedValue(value); | ||
} | ||
setDebouncedValue((prev) => prev != value ? value : prev); | ||
}, [value]); | ||
@@ -41,0 +39,0 @@ return debouncedValue; |
130089