import { DomSinks , DomSource , DomSources } from './' ; import { Component } from '@motorcycle/run' ; export function isolateDom < Sources extends DomSources , Sinks extends DomSinks > ( ComponentFn , key = createKey ( ) ) { return function ( sources ) : Sinks { const { dom } = sources ; const isolatedDom = dom . isolateSource ( dom , key ) ; const sinks = ComponentFn ( Object . assign ( { } , sources , { dom : isolatedDom } ) ) ; return Object . assign ( { } , sinks , { view$ : dom . isolateSink ( sinks . view$ , key ) } ) ; } ; } export function createKey ( ) { return Math . random ( ) . toString ( 36 ) . substr ( 2 , 6 ) ; }