/**
 * This module is private and deal with updating a graph object internal Immutable.Map
 */ import curry from 'lodash/curry' ; import isString from 'lodash/isString' ; import { Map } from 'immutable' ; import { throwInDev , throwTypeError } from '../throwInDev' ; private param { any } map return { bool } export function isMapElseThrow ( map ) { const test = Map . isMap ( map ) ; if ( ! test ) { throwTypeError ( 'Immutable.Map' , map , 'map' ) ; } return test ; } private param { any } key return { bool } export function isKeyElseThrow ( key ) { const test = isString ( key ) ; if ( ! test ) { throwInDev ( `key should be a string, was given ${ key && key . toString ( ) } of type ${ typeof key }` ) ; } return test ; } function param { string } key param { any } value param { Immutable . Map } map returns { Immutable . Map } export const set = curry ( ( key , value , map ) => { if ( isKeyElseThrow ( key ) && isMapElseThrow ( map ) ) { return map . set ( key , value ) ; } return map ; } ) ; function param { string } key param { Immutable . Map } map returns { any | null } export const get = curry ( ( key , map ) => { if ( isKeyElseThrow ( key ) && isMapElseThrow ( map ) ) { return map . get ( key ) ; } return null ; } ) ; function param { string } key param { Immutable . Map } map return { bool } export const has = curry ( ( key , map ) => { if ( isKeyElseThrow ( key ) && isMapElseThrow ( map ) ) { return map . has ( key ) ; } return false ; } ) ; function param { string } key param { Immutable . Map } map returns { Immutable . Map } export const deleteKey = curry ( ( key , map ) => { if ( isKeyElseThrow ( key ) && isMapElseThrow ( map ) ) { return map . delete ( key ) ; } return map ; } ) ;