import { fail , ObjectNode , ScalarNode , AnyNode , getStateTreeNodeSafe , AnyObjectNode , ComplexType , SimpleType } from "../../internal" ; internal hidden export function createObjectNode < C , S , T > ( type , parent , subpath , environment , initialValue ) { const existingNode = getStateTreeNodeSafe ( initialValue ) ; if ( existingNode ) { if ( existingNode . parent ) { throw fail ( `Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${ parent ? parent . path : "" }/${ subpath }', but it lives already at '${ existingNode . path }'` ) ; } if ( parent ) { existingNode . setParent ( parent , subpath ) ; } return existingNode ; } return new ObjectNode ( type , parent , subpath , environment , initialValue as C ) ; } internal hidden export function createScalarNode < C , S , T > ( type , parent , subpath , environment , initialValue ) { return new ScalarNode ( type , parent , subpath , environment , initialValue ) ; } internal hidden export function isNode ( value ) { return value instanceof ScalarNode || value instanceof ObjectNode ; }