-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Vue Devtools #116
feat: Vue Devtools #116
Conversation
🦋 Changeset detectedLatest commit: 4ee0210 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
95ed876
to
6dc7a52
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some early thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several changes, nice work tho 👍
packages/core/src/useForm/useForm.ts
Outdated
watch( | ||
() => ({ | ||
errors: errors.value, | ||
isValid: isValid.value, | ||
values: values, | ||
isSubmitting: isSubmitting.value, | ||
submitAttemptsCount: submitAttemptsCount.value, | ||
}), | ||
refreshInspector, | ||
{ | ||
deep: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the watcher inside registerForm
@@ -36,6 +36,7 @@ export type FormField<TValue> = { | |||
setTouched: (touched: boolean) => void; | |||
setErrors: (messages: Arrayable<string>) => void; | |||
displayError: () => string | undefined; | |||
form?: FormContext | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this to resolvedForm
for clarity.
@@ -191,7 +192,7 @@ export function useFormField<TValue = unknown>(opts?: Partial<FormFieldOptions<T | |||
form.setFieldDisabled(path, disabled); | |||
}); | |||
|
|||
return field; | |||
return { ...field, form }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to spread, just add the resolvedForm
to the FormField
type and then you could just set it as a prop here.
packages/dev-tools/src/registery.ts
Outdated
export function registerTextFieldWithDevtools(field: Omit<TextField, 'type'>) { | ||
const vm = initDevTools(); | ||
|
||
const id = field.getPath() ?? field.getName() ?? ''; | ||
const formId = field.form?.id; | ||
|
||
// if the field is part of a form, we need to register to add the field to the form | ||
if (formId && DEVTOOLS_FORMS[formId]) { | ||
DEVTOOLS_FORMS[formId].children = DEVTOOLS_FORMS[formId].children ?? []; | ||
DEVTOOLS_FORMS[formId].children.push({ | ||
...field, | ||
type: FIELD_TYPES.TextField, | ||
_vm: vm, | ||
}); | ||
} else { | ||
// if the field is a standalone field, we need to register it | ||
DEVTOOLS_FIELDS[id] = { ...field, type: FIELD_TYPES.TextField, _vm: vm }; | ||
} | ||
|
||
watch( | ||
() => ({ | ||
errors: field.errorMessage.value, | ||
isValid: !field.errorMessage.value, | ||
value: field.fieldValue.value, | ||
}), | ||
refreshInspector, | ||
{ | ||
deep: true, | ||
}, | ||
); | ||
|
||
onUnmounted(() => { | ||
delete DEVTOOLS_FIELDS[id]; | ||
refreshInspector(); | ||
}); | ||
|
||
refreshInspector(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid specific register
functions for now, let's just start with registerField
and registerForm
, no need to have withDevtools
as well because it is implied.
Change the function signature to be like this:
function registerField(field: FormField<unknown>, type: string) {
// ....
}
packages/dev-tools/src/types.ts
Outdated
export type TextField = ReturnType<typeof useTextField> & | ||
ReturnType<typeof useFormField<string | undefined>> & { | ||
type: (typeof FIELD_TYPES)['TextField']; | ||
}; | ||
|
||
export type CheckboxField = ReturnType<typeof useCheckbox> & | ||
ReturnType<typeof useFormField<string | undefined>> & { | ||
type: (typeof FIELD_TYPES)['Checkbox']; | ||
}; | ||
|
||
export type RadioField = ReturnType<typeof useRadioGroup> & | ||
ReturnType<typeof useFormField<string | undefined>> & { | ||
type: (typeof FIELD_TYPES)['Radio']; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't need those if you follow my suggestion.
packages/dev-tools/src/types.ts
Outdated
export interface PathState<TValue = unknown> { | ||
touched: boolean; | ||
dirty: boolean; | ||
valid: boolean; | ||
errors: string[]; | ||
value: TValue; | ||
} | ||
|
||
// Form state extending base state | ||
export interface FormState extends PathState { | ||
id: string; | ||
} | ||
|
||
// Field state extending base state | ||
export interface FieldState<TValue = unknown> extends PathState<TValue> { | ||
path: string; | ||
name: string; | ||
formId?: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to map types for those?
1c10ccb
to
26cecb7
Compare
commit: |
No description provided.