Skip to content

Commit

Permalink
feat: deprecate the 'required' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed May 11, 2020
1 parent 7af3ed2 commit 283caa0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/Observer.ts
@@ -1,7 +1,7 @@
import { computed, provide, h, defineComponent } from 'vue';
import { normalizeChildren } from './utils/vnode';
import { useForm } from './useForm';
import { ValidationFlags, SubmissionHandler } from './types';
import { ValidationFlags, SubmissionHandler, Flag } from './types';

export const ValidationObserver = defineComponent({
name: 'ValidationObserver',
Expand All @@ -24,7 +24,7 @@ export const ValidationObserver = defineComponent({
provide('$_veeObserver', form);
const unwrappedMeta = computed(() =>
Object.keys(meta).reduce((acc: ValidationFlags, key) => {
acc[key] = (meta as any)[key].value;
acc[key as Flag] = meta[key as Flag].value;

return acc;
}, {} as ValidationFlags)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Provider.ts
Expand Up @@ -63,7 +63,7 @@ export const ValidationProvider = defineComponent({

const unwrappedMeta = computed(() => {
return Object.keys(meta).reduce((acc, key) => {
acc[key] = meta[key as Flag].value;
acc[key as Flag] = meta[key as Flag].value;

return acc;
}, {} as ValidationFlags);
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/types.ts
Expand Up @@ -45,9 +45,7 @@ export interface ValidationFlags {
failed: boolean;
validated: boolean;
pending: boolean;
required: boolean;
changed: boolean;
[x: string]: boolean | undefined;
}

export interface VeeObserver {
Expand All @@ -74,7 +72,6 @@ export type Flag =
| 'failed'
| 'validated'
| 'pending'
| 'required'
| 'changed';

export interface FieldComposite {
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/useField.ts
@@ -1,6 +1,13 @@
import { watch, ref, Ref, isRef, reactive, computed, onMounted, toRefs, watchEffect } from 'vue';
import { validate } from './validate';
import { FormController, ValidationResult, MaybeReactive, FieldComposite, GenericValidateFunction } from './types';
import {
FormController,
ValidationResult,
MaybeReactive,
FieldComposite,
GenericValidateFunction,
Flag,
} from './types';
import { createFlags, normalizeRules, extractLocators } from './utils';
import { normalizeEventValue } from './utils/events';
import { unwrap } from './utils/refs';
Expand Down Expand Up @@ -222,7 +229,7 @@ function useMeta() {
return;
}

flags[key] = defaults[key];
flags[key as Flag] = defaults[key as Flag];
});
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/useForm.ts
Expand Up @@ -14,7 +14,6 @@ const mergeStrategies: Record<Flag, 'every' | 'some'> = {
changed: 'some',
passed: 'every',
failed: 'some',
required: 'some',
};

function computeMeta(fields: Ref<any[]>) {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils/factories.ts
Expand Up @@ -10,7 +10,6 @@ export function createFlags(): ValidationFlags {
invalid: false,
validated: false,
pending: false,
required: false,
changed: false,
passed: false,
failed: false,
Expand Down

0 comments on commit 283caa0

Please sign in to comment.