How to use the Seq function from immutable
Find comprehensive JavaScript immutable.Seq code examples handpicked from public code repositorys.
35 36 37 38 39 40 41 42 43 44
``` This might feel a little over the top at first but comes with a few advantages that are pivotal to >TreeUtils. As a matter of fact, all the functions in this lib, that give you a node or a collection of nodes don't return the actual >ImmutableJS values but the key paths to the substate where the resulting node(s) are located. A lot of operations become very trivial with key paths. Let's look at the >parent function. Determining the parent of a given node represented by a key path is as simple as this: ```js let nodePath = Immutable.Seq(['data', 'childNodes', 0, 'childNodes', 1]); let parentPath = nodePath.skipLast(2); ``` The actual retrieval of the >ImmutableJS values is left to you, but you will notice that working with key paths can be quite fun. Imagine you want to get value at key `content` of the next sibling of a given node. You could do this like so:
8
77
3
736 737 738 739 740 741 742 743 744 745 746 747
*/ var Immutable = require('immutable'); var Iterable = Immutable.Iterable; var Iterator = Iterable.Iterator; var Seq = Immutable.Seq; var Map = Immutable.Map; var Record = Immutable.Record;
0
1
0
immutable.Map is the most popular function in immutable (1575 examples)