Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 1274df7

Browse files
authored
Merge pull request #209 from asigloo/bugfix/fix-vue-warns
fix: removed all warnings
2 parents b1eeb5f + 5661b79 commit 1274df7

File tree

12 files changed

+89
-16
lines changed

12 files changed

+89
-16
lines changed

dev/vue/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="card p-6 mr-4">
77
<dynamic-form
88
:form="form"
9-
@submited="handleSubmit"
9+
@submitted="handleSubmit"
1010
@changed="valueChanged"
1111
@error="handleError"
1212
>

src/components/checkbox-input/CheckboxInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const props = {
1414
1515
export default defineComponent({
1616
name: 'asCheckboxInput',
17+
inheritAttrs: false,
1718
props,
1819
setup(props, { emit }) {
1920
const { onCheck, onFocus, onBlur } = useInputEvents(props, emit);

src/components/dynamic-form/DynamicForm.vue

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
v-for="control in controls"
1212
:key="control.name"
1313
:control="control"
14-
:submited="submited"
1514
:forceValidation="forceValidation"
1615
@change="valueChange"
1716
@blur="onBlur"
@@ -61,15 +60,12 @@ import {
6160
InputType,
6261
ValidationEvent,
6362
InputEvent,
63+
FormChanges,
6464
} from '@/core/models';
6565
import { dynamicFormsSymbol } from '@/useApi';
66-
import {
67-
deepClone,
68-
hasValue,
69-
isEvent,
70-
removeEmpty,
71-
} from '@/core/utils/helpers';
66+
import { deepClone, hasValue, removeEmpty } from '@/core/utils/helpers';
7267
import { FieldControl } from '@/core/factories';
68+
import { useDebounceFn } from '@/composables/use-debounce';
7369
7470
const props = {
7571
form: {
@@ -86,6 +82,7 @@ const components = {
8682
*/
8783
export default defineComponent({
8884
name: 'asDynamicForm',
85+
inheritAttrs: false,
8986
props,
9087
components,
9188
setup(props, ctx) {
@@ -197,14 +194,20 @@ export default defineComponent({
197194
return updatedCtrl;
198195
}
199196
200-
function valueChange(event: any) {
197+
function emitChanges(changes: FormChanges) {
198+
ctx.emit('change', changes);
199+
}
200+
201+
const debounceEmitChanges = useDebounceFn(emitChanges, 300);
202+
203+
function valueChange(event: InputEvent) {
201204
if (hasValue(event.value)) {
202205
const updatedCtrl = findControlByName(event.name);
203206
if (updatedCtrl) {
204207
updatedCtrl.value = event.value as string;
205208
updatedCtrl.dirty = true;
206209
}
207-
ctx.emit('change', formValues.value);
210+
debounceEmitChanges(formValues.value);
208211
}
209212
}
210213

src/components/dynamic-input/DynamicInput.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
/* eslint-disable @typescript-eslint/no-use-before-define */
33
4-
import { defineComponent, PropType, computed, h, inject } from 'vue';
4+
import { defineComponent, PropType, computed, h } from 'vue';
55
import TextInputComponent from '../text-input/TextInput.vue';
66
import SelectInputComponent from '../select-input/SelectInput.vue';
77
import TextAreaInputComponent from '../text-area-input/TextAreaInput.vue';
@@ -28,7 +28,7 @@ import {
2828
InputEvent,
2929
} from '@/core/models';
3030
31-
import { isArray, isEvent, isObject } from '@/core/utils/helpers';
31+
import { isArray, isObject } from '@/core/utils/helpers';
3232
import { useInputEvents } from '@/composables/input-events';
3333
3434
const components = {
@@ -61,9 +61,10 @@ export type ControlAttribute<T extends InputType> = {
6161
export default defineComponent({
6262
name: 'asDynamicInput',
6363
components,
64+
inheritAttrs: false,
6465
props,
6566
setup(props, { emit, slots }) {
66-
const { onFocus, onInput, onChange, onBlur } = useInputEvents(props, emit);
67+
const { onFocus, onInput, onBlur } = useInputEvents(props, emit);
6768
6869
let component;
6970

src/components/number-input/NumberInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const props = {
1414
1515
export default defineComponent({
1616
name: 'asNumberInput',
17+
inheritAttrs: false,
1718
props,
1819
setup(props, { emit }) {
1920
const { onInput, onChange, onFocus, onBlur } = useInputEvents(props, emit);

src/components/radio-input/RadioInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const props = {
1414
1515
export default defineComponent({
1616
name: 'asRadioInput',
17+
inheritAttrs: false,
1718
props,
1819
setup(props, { emit }) {
1920
const { onChange, onInput, onFocus, onBlur } = useInputEvents(props, emit);

src/components/select-input/SelectInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const props = {
1515
1616
export default defineComponent({
1717
name: 'asSelectInput',
18+
inheritAttrs: false,
1819
props,
1920
setup(props, { emit }) {
2021
return () => {

src/components/text-area-input/TextAreaInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const props = {
1313
1414
export default defineComponent({
1515
name: 'asTextAreaInput',
16+
inheritAttrs: false,
1617
props,
1718
setup(props, { emit }) {
1819
const { onInput, onChange, onFocus, onBlur } = useInputEvents(props, emit);

src/components/text-input/TextInput.vue

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const props = {
2323
2424
export default defineComponent({
2525
name: 'asTextInput',
26+
inheritAttrs: false,
2627
props,
2728
setup(props, { emit }) {
2829
const { onInput, onChange, onFocus, onBlur, getClasses } = useInputEvents(

src/composables/input-events.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
12
import { computed, ComputedRef, watch } from 'vue';
23
import { hasValue } from '../core/utils/helpers';
34

@@ -13,7 +14,7 @@ interface InputEventsComposition {
1314
getClasses: ComputedRef<(string | { [key: string]: boolean })[]>;
1415
}
1516

16-
export function useInputEvents(props: any, emit: any): InputEventsComposition {
17+
export function useInputEvents(props, emit): InputEventsComposition {
1718
const { validate, getValidationClasses } = useInputValidation(props, emit);
1819

1920
function onInput($event: Event): void {
@@ -72,13 +73,16 @@ export function useInputEvents(props: any, emit: any): InputEventsComposition {
7273
watch(
7374
() => props?.control?.value,
7475
(curr, prev) => {
75-
if (prev !== undefined && hasValue(curr) && curr !== prev) {
76+
if (hasValue(curr) && curr !== prev) {
7677
emit('change', {
7778
name: props.control.name,
7879
value: props.control.value,
7980
});
8081
}
8182
},
83+
{
84+
immediate: true,
85+
},
8286
);
8387

8488
return {

src/composables/use-debounce.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
export type FunctionArgs<Args extends any[] = any[], Return = void> = (
4+
...args: Args
5+
) => Return;
6+
7+
export interface FunctionWrapperOptions<
8+
Args extends any[] = any[],
9+
This = any
10+
> {
11+
fn: FunctionArgs<Args, This>;
12+
args: Args;
13+
thisArg: This;
14+
}
15+
16+
export type EventFilter<Args extends any[] = any[], This = any> = (
17+
invoke: () => void,
18+
options: FunctionWrapperOptions<Args, This>,
19+
) => void;
20+
21+
/**
22+
* @internal
23+
*/
24+
export function createFilterWrapper<T extends FunctionArgs>(
25+
filter: EventFilter,
26+
fn: T,
27+
) {
28+
function wrapper(this: any, ...args: any[]) {
29+
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
30+
}
31+
32+
return (wrapper as any) as T;
33+
}
34+
35+
export const bypassFilter: EventFilter = invoke => {
36+
return invoke();
37+
};
38+
39+
export function debounceFilter(ms: number): EventFilter {
40+
if (ms <= 0) return bypassFilter;
41+
42+
let timer: ReturnType<typeof setTimeout> | undefined;
43+
44+
const filter: EventFilter = invoke => {
45+
if (timer) clearTimeout(timer);
46+
47+
timer = setTimeout(invoke, ms);
48+
};
49+
50+
return filter;
51+
}
52+
53+
export function useDebounceFn<T extends FunctionArgs>(fn: T, ms = 200): T {
54+
return createFilterWrapper(debounceFilter(ms), fn);
55+
}

src/core/models.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export type FormFields = {
1919
[key: string]: InputType;
2020
};
2121

22+
export type FormChanges = {
23+
[key: string]: string | number | null | undefined;
24+
};
2225
export interface DynamicForm {
2326
id: string;
2427
fields: FormFields;
@@ -36,7 +39,7 @@ export type ValidationErrors = {
3639
};
3740

3841
export type BindingObject = {
39-
[key: string]: any;
42+
[key: string]: never;
4043
};
4144

4245
export interface ValidatorFn {
@@ -53,6 +56,7 @@ export interface FormValidator {
5356

5457
export interface InputEvent {
5558
name: string;
59+
value?: unknown;
5660
}
5761

5862
export type ValidationEvent = InputEvent & {

0 commit comments

Comments
 (0)