Skip to content

How to change the evaluation order of side-effects? #227

Answered by Tao-VanJS
ceving asked this question in Q&A
Discussion options

You must be logged in to vote

I can think of 2 ways to solve the problem while keeping valid a state.

  1. Make the validation result in sync with the text we're validating:
let valid = van.derive(() => ({
  result: validation(text.val)
  for: text.val
}))
van.derive(() => {
  if (valid.val.result) state.val = valid.val.for
})
  1. Update state asynchronously:
let valid = van.derive(() => validation(text.val))

van.derive(() => {
  if (valid.val) setTimeout(() => state.val = text.val)
})

Let me know if one of the solutions can work for you.

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@ceving
Comment options

@ceving
Comment options

Comment options

You must be logged in to vote
1 reply
@ceving
Comment options

Comment options

You must be logged in to vote
2 replies
@ceving
Comment options

@Tao-VanJS
Comment options

Answer selected by Tao-VanJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants