You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT: forgot mobx.observable([]) in initial version
The 2nd example was not using mobx.observable. Sorry for this copy'n'paste error. It's now fixed above. Please note that this brought up another difference for the empty observable array.
The text was updated successfully, but these errors were encountered:
After a few more thoughts and debug outputs, it looks to me that an array property of an observable object is not imitating array as good as observableArray does.
Some more differences between the 5 examples:
all but the 4th return true for Array.isArray(x) (but all return true for x instanceof Array)
browser/nodejs console.log output an array literal for all except the wrong one (which results in type t or ObservableArray {})
Object.keys output: ["0","1","2","3"]vs []
Object.getOwnPropertyNames output: ["0","1","2","3","length"] vs ["$mobx"]
native toString toString.call(x) returns [object Array] vs [object Object]
2nd example: nativeArray.concat(observableArray) results in [observableArray] as far as Array.isArray(observableArray) === false
3rd example: concating native array, same as 1st example.
4th example: you get the same result as in 2nd example but after assigning [observableArray] to observable property, it is being automatically converted to ObservableArray so you get ObservableArray["a", observableArray], then ["b" ObservableArray["a", observableArray]] becomes ObservableArray["b", ObservableArray["a", observableArray]] and so on.
5th example: you converting ObservableArray to Array before passing it to concat, so you get native array that, converted to ObservableArray after assining it to observable prop
Those 5 example cases should all have the same output, but the 2nd and 4th are currently different:
Output:
@mweststrate pointed out on gitter:
EDIT: forgot mobx.observable([]) in initial version
The 2nd example was not using mobx.observable. Sorry for this copy'n'paste error. It's now fixed above. Please note that this brought up another difference for the empty observable array.
The text was updated successfully, but these errors were encountered: