immutable-to-js
Function to convert an immutable-js value to a regular JavaScript value. If the given value is not an immutable-js value, it is simply returned.
Use Case
When using Immutable.fromJS(value)
on arbitrary values a
non-immutable value can be returned (e.g., Immutable.fromJS(5) === 5
). To then convert the value back to a regular js object, we have
to first make sure the value is an immutable value and then call
.toJS()
on it. This module provides a static toJS(value)
function
that performs the necessary type checking to guarantee the return value
is a regular js object.
var value = Immutable; // May result in immutable, may notvar unwrapped = ; // Guarantee value is not immutable
Example
var toJS = ;var Immutable = ; ; // -> { foo: 1 }; // -> [1, 2, 3]; // -> "hello"; // -> 5
API
var toJS = ;
toJS(value)
Convert value
to a regular js value. If value
is not an
immutable-js value, it is simply returned.