import type { Readable } from 'svelte/store' ; import { readable } from 'svelte/store' ; function noop ( ) { } type Cleanup = ( ) => void ; type Unsubscriber = ( ) => void ; type CleanupSubscriber < T > = ( value : T ) => Cleanup | void ; type p < l , r > = ( v : l ) => Readable < r > ; export function unnest < A , B > ( store , ... arr ) ; export function unnest < A , B , C > ( store , ... arr ) ; export function unnest < A , B , C , D > ( store , ... arr ) ; export function unnest < A , B , C , D , E > ( store , ... arr ) ; export function unnest ( store , ... arr ) { const max = arr . length - 1 ; return readable ( null , set => { const l = ( i ) => p => { const q = arr [ i ] ( p ) ; if ( ! q ) set ( null ) ; else return i === max ? q . subscribe ( set ) : subscribe_cleanup ( q , l ( i + 1 ) ) ; } ; return subscribe_cleanup ( store , l ( 0 ) ) ; } ) ; } function subscribe_cleanup < T > ( store , run ) { let cleanup = noop ; const unsub = store . subscribe ( v => { cleanup ( ) ; cleanup = run ( v ) || noop ; } ) ; return ( ) => { cleanup ( ) ; unsub ( ) ; } ; }