Skip to content

Reactions to nested Atoms #7

Answered by vanifatovvlad
slimshader asked this question in Q&A
Discussion options

You must be logged in to vote

The reactions are executed in two cases:

  1. on creation;
  2. on the next frame after any dependant atom changed.

In this sample, a value "5" is printed immediately when creating a reaction. Values "6" and "7" are set during one frame. They trigger a reaction, but the reaction itself is executed once on the next frame and use latest values (so "7" is printed).

The value "6" will be printed if the values are set in different frames, or if you force actualize a reaction.

private IEnumerator Start()
{
    VM = new ViewModel() {IntValue = 5};

    Atom.Reaction(() => Debug.Log($"Int value {VM.IntValue}"));

    VM.IntValue = 6;
    yield return null; // skip one frame

    VM = new ViewModel() {Int…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by vanifatovvlad
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4 on July 21, 2021 13:37.