Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over Map in immutablejs

What is the equivalent to Object.entries() in Immutablejs Map. Basically, I enumerate the object's key/value pairs to render a presentational component

{
  Object.entries(filteredNetworks)
  .map(([key, value]) =><option key={key} value={key}>{value}</option>)
}

Now, with the filteredNetworks being an immutable Map, how can i do the same ? (without using .toJS())

like image 246
selvagsz Avatar asked Oct 18 '16 07:10

selvagsz


1 Answers

Based on: https://facebook.github.io/immutable-js/docs/#/Iterable/map

{
  filteredNetworks.map(
  (value, key) => <option key={key} value={key}>{value}</option>
  )
}

note that argument order changed for the mapper function.

Another option using Entry Sequence could be

{
   filteredNetworks.entrySeq().map(
     .map(([key, value]) =><option key={key} value={key}>{value}</option>)
   )
}

fiddling around at https://jsfiddle.net/3r866to3/

like image 163
Logicomancer Avatar answered Oct 27 '22 04:10

Logicomancer