September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's implement a function that prints set values only if the set argument value has changed since the last time it was called:
const printValues = (set) => { if (!set.equals(printValues.prev)) { printValues.prev = set; set .valueSeq() .map(v => v.toJS()) .forEach(v => console.log(v)); }};
If this code looks familiar, it's because you learned about this change detection technique in the previous chapter. The reason that we need this here is so that we can see how sets change as we add values to them:
const myOrderedSet = OrderedSet.of( Map.of('one', 1), Map.of('two', 2));console.log('myOrderedSet');printValues(myOrderedSet);// -> myOrderedSet// -> { one: 1 }// -> { two: 2 }console.log('adding 3');printValues(myOrderedSet.add(Map.of('three', ...Read now
Unlock full access