Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid unwanted key cast from number to string in Immutable.js

I'm trying to use Immutable in a project with reactjs and flux.

Let's say I have a .js file with the code

console.log ( Immutable.Map({1: 2}).toString() )

I browserify this script and run it from the browser (Google Chrome), the result is:

"Map { "1": 2 }"

notice that the key, 1, is now a string, not a number.

If I try the same code directly in the console of the site http://facebook.github.io/immutable-js/ I get the correct result:

"Map { 1: 2 }"

Why is this happening and what can I do to get the correct result (key as number) in my script?

I'm using node v0.10.26, Browserify 5.12.0 and immutable 3.7.1

like image 923
javier Avatar asked Apr 04 '15 19:04

javier


1 Answers

Giving Map an array of key value pairs seems to do the trick:

> Immutable.Map([[1, 2]]).toString()
'Map { 1: 2 }'

see https://facebook.github.io/immutable-js/docs/#/Map/Map for more info

like image 176
brianjob Avatar answered Nov 09 '22 09:11

brianjob