Skip to content

Handling collections #5

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

You must be logged in to vote

Hi,

Yes that's right. Atom doesn't track object modification. Reaction will be triggered only when new value has been set for atom.

However, you can write your own collection type that will trigger reactions when new items are added.

[Atom] public AtomList<Todo> Todos { get; set; } = new AtomList<Todo>();
incrementButton.onClick.AddListener(() =>
{
       Todos.Add(new Todo());
});

Atom.Reaction(() => counterText.text = "Unifinished: " + UnfinishedTodoCount);
public class AtomList<T> : IEnumerable<T>
{
    private readonly MutableAtom<List<T>> _list = Atom.Value(new List<T>());

    public void Add(T value)
    {
        _list.Value.Add(value);
        _list.Invalidate();
    }

    public 

Replies: 3 comments 1 reply

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
1 reply
@vanifatovvlad
Comment options

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 #1 on July 21, 2021 13:36.