import curry from 'lodash/curry' ; import flow from 'lodash/flow' ; import isNumber from 'lodash/isNumber' ; import { throwInDev , throwTypeError } from '../throwInDev' ; import { PositionRecord } from '../../constants/flowdesigner.model' ; import { PositionRecord as PositionRecordType } from '../../customTypings/index.d' ; desc example example example typedef { Immutable . Record } PositionRecord param { * } position return { bool } export function isPosition ( position ) { if ( position && position instanceof PositionRecord ) { return true ; } return false ; } param { * } position return { bool } export function isPositionElseThrow ( position ) { const test = isPosition ( position ) ; if ( ! test ) { throwTypeError ( 'PositionRecord' , position , 'Position' ) ; } return test ; } param { PositionRecord } position return { number } export function getXCoordinate ( position ) { if ( isPositionElseThrow ( position ) ) { return position . get ( 'x' ) ; } return null ; } function param { number } x param { PositionRecord } position return { PositionRecord } export const setXCoordinate = curry ( ( x , position ) => { if ( isPositionElseThrow ( position ) && isNumber ( x ) ) { return position . set ( 'x' , x ) ; } throwInDev ( `x should be a number, was given ${ x && x . toString ( ) } of type ${ typeof x }` ) ; return position ; } ) ; param { PositionRecord } position return { number } export function getYCoordinate ( position ) { if ( isPositionElseThrow ( position ) ) { return position . get ( 'y' ) ; } return null ; } param { number } y param { PositionRecord } position return { PositionRecord } export const setYCoordinate = curry ( ( y , position ) => { if ( isPositionElseThrow ( position ) && isNumber ( y ) ) { return position . set ( 'y' , y ) ; } throwInDev ( `y should be a number, was given ${ y && y . toString ( ) } of type ${ typeof y }` ) ; return position ; } ) ; param { number } x param { number } y return { PositionRecord } export const create = curry ( ( x , y ) => flow ( [ setXCoordinate ( x ) , setYCoordinate ( y ) ] ) ( new PositionRecord ( ) ) ) ;