@@ -40,13 +40,14 @@ Vest integrates naturally with Svelte's reactive stores and reactive statements,
4040 let result = suite.get();
4141
4242 function validateField(fieldName) {
43- suite.afterEach((res ) => {
44- result = res ;
43+ suite.afterEach(() => {
44+ result = suite.get() ;
4545 }).run(formData, fieldName);
4646 }
4747
4848 function handleSubmit() {
49- suite.afterEach((res) => {
49+ suite.afterEach(() => {
50+ const res = suite.get();
5051 result = res;
5152
5253 if (!res.hasErrors()) {
@@ -127,13 +128,14 @@ Create a reactive store for your validation results:
127128 function validateField(fieldName, value) {
128129 formData.update(data => ({ ...data, [fieldName]: value }));
129130
130- suite.afterEach((res ) => {
131- validationResult.set(res );
131+ suite.afterEach(() => {
132+ validationResult.set(suite.get() );
132133 }).run($formData, fieldName);
133134 }
134135
135136 function handleSubmit() {
136- suite.afterEach((res) => {
137+ suite.afterEach(() => {
138+ const res = suite.get();
137139 validationResult.set(res);
138140
139141 if (!res.hasErrors()) {
@@ -177,8 +179,8 @@ Use Svelte's reactive statements for automatic validation:
177179
178180 // Automatically validate when username changes
179181 $: if (username !== undefined) {
180- suite.afterEach((res ) => {
181- result = res ;
182+ suite.afterEach(() => {
183+ result = suite.get() ;
182184 }).run({ username }, 'username');
183185 }
184186</script>
@@ -219,8 +221,8 @@ Handle async validations with Svelte's reactivity:
219221 async function checkUsername() {
220222 isChecking = true;
221223
222- suite.afterEach((res ) => {
223- result = res ;
224+ suite.afterEach(() => {
225+ result = suite.get() ;
224226 isChecking = false;
225227 }).run({ username }, 'username');
226228 }
@@ -322,8 +324,8 @@ export function createValidationStore(suite, initialData = {}) {
322324
323325 const currentData = get (formData);
324326 suite
325- .afterEach (res => {
326- result .set (res );
327+ .afterEach (() => {
328+ result .set (suite . get () );
327329 isValidating .set (false );
328330 })
329331 .run (currentData, fieldName);
@@ -334,8 +336,8 @@ export function createValidationStore(suite, initialData = {}) {
334336
335337 const currentData = get (formData);
336338 suite
337- .afterEach (res => {
338- result .set (res );
339+ .afterEach (() => {
340+ result .set (suite . get () );
339341 isValidating .set (false );
340342 })
341343 .run (currentData);
@@ -445,8 +447,8 @@ Vest works great with [TypeScript](/docs/typescript_support) in Svelte:
445447 let result: SuiteResult = suite.get();
446448
447449 function validateField(fieldName: keyof FormData): void {
448- suite.afterEach((res ) => {
449- result = res ;
450+ suite.afterEach(() => {
451+ result = suite.get() ;
450452 }).run(formData, fieldName);
451453 }
452454</script>
@@ -478,7 +480,7 @@ Use debouncing for async or expensive validations:
478480 import { debounce } from './utils';
479481
480482 const validateUsername = debounce((value) => {
481- suite.afterEach(setResult).run({ username: value }, 'username');
483+ suite.afterEach(() => setResult(suite.get()) ).run({ username: value }, 'username');
482484 }, 500);
483485
484486 $: validateUsername(username);
0 commit comments