MCPcopy Create free account
hub / github.com/formkit/formkit / next

Function next

packages/validation/src/validation.ts:302–351  ·  view source on GitHub ↗
(async: boolean, result: boolean | null)

Source from the content-addressed store, hash-verified

300 validation.state = null
301
302 function next(async: boolean, result: boolean | null): void {
303 if (state.input !== currentRun) return
304 state.isPassing = state.isPassing && !!result
305 validation.queued = false
306 const newDeps = node.stopObserve()
307 const diff = diffDeps(validation.deps, newDeps)
308 applyListeners(
309 node,
310 diff,
311 function revalidate() {
312 // Event callback for when the deps change:
313 try {
314 node.store.set(validatingMessage)
315 } catch (e) {}
316 validation.queued = true
317 if (state.rerun) clearTimeout(state.rerun)
318 state.rerun = setTimeout(
319 validate,
320 0,
321 node,
322 validations,
323 state
324 ) as unknown as number
325 },
326 'unshift' // We want these listeners to run before other events are emitted so the 'state.validating' will be reliable.
327 )
328 validation.deps = newDeps
329
330 validation.state = result
331 if (result === false) {
332 createFailedMessage(validation, removeImmediately || async)
333 } else {
334 removeMessage(validation)
335 }
336 if (validations.length > current + 1) {
337 const nextValidation = validations[current + 1]
338 if (
339 (result || nextValidation.force || !nextValidation.skipEmpty) &&
340 nextValidation.state === null
341 ) {
342 // If the next rule was never run then it has not been observed so it could never
343 // run again on its own.
344 nextValidation.queued = true
345 }
346 run(current + 1, validations, state, removeImmediately || async, complete)
347 } else {
348 // The validation has completed
349 complete()
350 }
351 }
352 if (
353 (!empty(node.value) || !validation.skipEmpty) &&
354 (state.isPassing || validation.force)

Callers 15

setToFooFunction · 0.85
changeAttrsFunction · 0.85
plugin.spec.tsFile · 0.85
middlewareFunction · 0.85
createI18nPluginFunction · 0.85
errors.tsFile · 0.85
store.spec.tsFile · 0.85
dispatcher.spec.tsFile · 0.85
callbackFunction · 0.85
middlewareFunction · 0.85
node.spec.tsFile · 0.85
decodeErrorsFunction · 0.85

Calls 5

diffDepsFunction · 0.90
applyListenersFunction · 0.90
createFailedMessageFunction · 0.85
runFunction · 0.85
removeMessageFunction · 0.70

Tested by 9

setToFooFunction · 0.68
changeAttrsFunction · 0.68
middlewareFunction · 0.68
callbackFunction · 0.68
middlewareFunction · 0.68
hookFunction · 0.68
setToFooFunction · 0.68
changeAttrsFunction · 0.68
middlewareFunction · 0.68