import { createNode , is , step , Domain , Scope , CompositeName , Unit , Node , } from 'effector' ; export const LOGGER_DOMAIN_NAME = '@effector-logger' ; export function createName ( composite ) { return composite . path . filter ( ( name ) => name !== LOGGER_DOMAIN_NAME ) . join ( '/' ) ; } export function getPath ( unit ) { return ( unit as any ) . defaultConfig ?. loc ?. file ?? ' ' ; } function watchDomain ( unit , domain , fn ) { if ( is . store ( unit ) ) { fn ( unit . getState ( ) ) ; } const watchUnit = is . store ( unit ) ? unit . updates : unit ; ( watchUnit as any ) . watch ( fn ) ; } function watchScope ( unit , scope , fn ) { if ( is . store ( unit ) ) { fn ( scope . getState ( unit ) ) ; } const node = createNode ( { node : [ step . run ( { fn } ) ] } ) ; const watchUnit = is . store ( unit ) ? unit . updates : unit ; const id = ( watchUnit as any ) . graphite . id ; const links = ( ( scope as any ) . additionalLinks [ id ] = ( scope as any ) . additionalLinks [ id ] || [ ] ) ; links . push ( node ) ; } export function watch ( unit , source , fn ) { if ( is . domain ( source ) ) { watchDomain ( unit , source , fn ) ; } else { watchScope ( unit , source , fn ) ; } }