Whats the difference between
@observable
ObservableList<MatchClass> listOfMatches = ObservableList<MatchClass>();
and
@observable
List<MatchClass> listOfMatches = [];
List will not notify Mobx that a value has changed when you do:
listOfMatches[0] = match;
But both will work when you do:
listOfMatched = []
+1 to what @rrousselGit mentioned. Additionally it is worth thinking of MobX as a system that reports change in values.
@observable, you are hinting your interest in the change in value for that field. So anytime that field changes value, MobX will notify the reactions.List<T> does not have observability built in. If you change the items, MobX cannot know that the list items changed. However an ObservableList<T> is aware of such changes, like adding, removal, modification of an item at an index, etc. @observable List<T> when you are sure you are only interested in reference changes to the entire list. @observable ObservableList<T> when you not only care about reference changes to the list but also changes in the contents (add/remove/update).HTH.
Additionally, note that you can do:
List<Foo> foo = ObservableList<Foo>()
And whats the difference between
ObservableList<Foo> foo = ObservableList<Foo>()
and
List<Foo> foo = ObservableList<Foo>()
?
Using it as ObservableList<T> is preferred as you want to be explicit about the type of the list. If you want to hide the specific type, go with the List<T> approach. Although the consumers of your code may not know that an ObservableList<T> is being used. This is good to hide that detail for your consumers, say a third party library that only works with List<T>.
Most helpful comment
+1 to what @rrousselGit mentioned. Additionally it is worth thinking of MobX as a system that reports change in values.
@observable, you are hinting your interest in the change in value for that field. So anytime that field changes value, MobX will notify the reactions.List<T>does not have observability built in. If you change the items, MobX cannot know that the list items changed. However anObservableList<T>is aware of such changes, like adding, removal, modification of an item at an index, etc.@observable List<T>when you are sure you are only interested in reference changes to the entire list.@observable ObservableList<T>when you not only care about reference changes to the list but also changes in the contents (add/remove/update).HTH.