Skip to content

Commit

Permalink
feat: cache all the vee-validate event handlers on the provider instance
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Sep 18, 2019
1 parent 515fe7b commit 6dc9fad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type withProviderPrivates = VueConstructor<
_veeWatchers: Record<string, Function>;
$veeDebounce?: number;
$veeHandler?: Function;
$veeOnInput?: Function;
$veeOnBlur?: Function;
$vnode: VNodeWithVeeContext;
}
>;
Expand Down
22 changes: 15 additions & 7 deletions src/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,23 @@ export function computeModeSetting(ctx: ProviderInstance) {

// Creates the common handlers for a validatable context.
export function createCommonHandlers(vm: ProviderInstance) {
const onInput = (e: any) => {
vm.syncValue(e); // track and keep the value updated.
vm.setFlags({ dirty: true, pristine: false });
};
if (!vm.$veeOnInput) {
vm.$veeOnInput = (e: any) => {
vm.syncValue(e); // track and keep the value updated.
vm.setFlags({ dirty: true, pristine: false });
};
}

const onInput = vm.$veeOnInput;

if (!vm.$veeOnBlur) {
vm.$veeOnBlur = () => {
vm.setFlags({ touched: true, untouched: false });
};
}

// Blur event listener.
const onBlur = () => {
vm.setFlags({ touched: true, untouched: false });
};
const onBlur = vm.$veeOnBlur;

let onValidate = vm.$veeHandler;
const mode = computeModeSetting(vm);
Expand Down

0 comments on commit 6dc9fad

Please sign in to comment.