import { patchAppendChildAndInsertBefore } from './lib/utils/patch-append-insert' ; import { registerCustomElement } from './lib/elements/register-custom-element' ; import { EventContract } from './lib/tsaction/event_contract' ; import { initRouter } from './lib/router/router' ; import { ROUTES } from './routes' ; import { registerDataCacheElement } from './lib/data-cache/element' ; const contract = new EventContract ( document . documentElement , [ 'click' , ] ) ; contract . listen ( ) ; patchAppendChildAndInsertBefore ( ) ; function loadElement ( module ) { let name = '' ; if ( module . startsWith ( 'app-' ) ) { name = module . substr ( 4 ) ; } switch ( name ) { case 'product-list' : return import ( './app/components/product-list/product-list' ) ; case 'product-alerts' : return import ( './app/components/product-alerts/product-alerts' ) ; case 'product-details' : return import ( './app/components/product-details/product-details' ) ; default : throw new Error ( `Unknown component module ${ module }` ) ; } } function loadShell ( ) { return import ( './app/shell/shell' ) ; } function loadPage ( module ) { let name = '' ; if ( module . startsWith ( 'page-' ) ) { name = module . substr ( 5 ) ; } switch ( name ) { case 'index' : return import ( './app/pages/index/index' ) ; case 'products-id' : return import ( './app/pages/products/_id/index' ) ; case 'cart' : return import ( './app/pages/cart/index' ) ; case 'shipping' : return import ( './app/pages/shipping/index' ) ; default : throw new Error ( `Unknown page module ${ module }` ) ; } } function initializeSeenElements ( ) { const scriptEl = document . getElementById ( '_elements' ) ; const elements = JSON . parse ( scriptEl . textContent ) ; ( document as any ) . _seenElements = new Map ( ) ; ( document as any ) . _nextCompId = Object . keys ( elements ) . length ; for ( const element of Object . keys ( elements ) ) { ( document as any ) . _seenElements . set ( element , elements [ element ] ) ; } } /**
 * Parse the Ivy Element metadata and load shell Custom Elements
 * on the client that lazily bootstrap the actual component.
 */ function registerLazyCustomElements ( elementsMetadata ) { for ( let i = 0 ; i < elementsMetadata . length - 1 ; ) { const localName = elementsMetadata [ i ++ ] ; const inputsArray = elementsMetadata [ i ++ ] ; const inputs = { } ; for ( let j = 0 ; j < inputsArray . length - 1 ; ) { const propName = inputsArray [ j ++ ] ; const templateName = inputsArray [ j ++ ] ; inputs [ propName ] = templateName ; } const componentType = { } as any ; componentType . ngComponentDef = { inputs } ; let loader = loadElement ; if ( localName == 'shell-root' ) { loader = loadShell ; } else if ( localName . startsWith ( 'page-' ) ) { loader = loadPage ; } registerCustomElement ( document , customElements , ( ) => import ( './lib/elements/angular-ivy-bits' ) , localName , componentType , undefined , loader , contract ) ; } } const ELEMENTS_METADATA = [ 'shell-root' , [ ] , 'page-index' , [ ] , 'page-products-id' , [ 'id' , 'id' ] , 'page-cart' , [ ] , 'page-shipping' , [ ] , 'app-product-list' , [ 'category' , 'category' ] , 'app-product-alerts' , [ 'price' , 'price' ] , 'app-product-details' , [ 'id' , 'id' ] , ] ; initializeSeenElements ( ) ; registerDataCacheElement ( ) ; registerLazyCustomElements ( ELEMENTS_METADATA ) ; initRouter ( ROUTES , contract ) ;