Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immutable.Set.contains returns false

I want to create an Immutable Set of paths. A path, in my case, is just an array of strings. So let's say we have the following paths.

var paths = [["a"], ["a", "b", "c"]];

I then create the Immutable Set like this

var selectedPaths = Immutable.Set(paths);

Although selectedPaths.first() returns ["a"], I cannot understand why selectedPaths.contains(["a"]) returns false.

EDIT: Well, I got an answer as to why this is happening, but I still cannot get it to work as I need it to.

SOLUTION: As @Alnitak has stated, I solved this by comparing a path to Immutable.List(["a"]) instead of a simple array

like image 275
XeniaSis Avatar asked Jan 25 '16 14:01

XeniaSis


1 Answers

According to the docs, Immutable uses the Immutable.is() function to perform equality checks, but that .is() check only performs "value comparison" checks when given other Immutable.* objects, and not native JS arrays, for which it performs a "reference comparison" check.

Therefore, try storing your inner values as an Immutable.List instead of as a plain JS array.

like image 60
Alnitak Avatar answered Sep 17 '22 13:09

Alnitak