import { Injectable , NgZone , Renderer2 } from '@angular/core' ; import { command , DomEventArg , FnArg , MessageBus , PrimitiveArg , RendererAdapter2 , RendererMethods2 , RendererType2Arg , Serializer , StoreObjectArg } from '../shared' ; import { ServerGlobalEvents } from './server-global-events' ; @ Injectable ( ) export class ServerRendererAdapter2 extends RendererAdapter2 { constructor ( private bus , private serializer , private globalEvents , private ngZone ) { super ( ) ; } begin ( ) { this . callBrowserRenderer ( 'begin' ) ; } end ( ) { this . callBrowserRenderer ( 'begin' ) ; } addClass ( rendererArg , elArg , nameArg ) { this . callBrowserRenderer ( 'addClass' , ... arguments ) ; } appendChild ( rendererArg , parentArg , newChildArg ) { this . callBrowserRenderer ( 'appendChild' , ... arguments ) ; } event ( rendererArg , targetElArg , targetNameArg , eventNameArg , eventArg ) { const [ renderer , targetEl , targetName , eventName , event ] = this . deserialize ( ... arguments ) ; const globalEvent = typeof targetName === 'string' ? `${ targetName }:${ eventName }` : null ; this . ngZone . run ( ( ) => { const clickEvent = { isTrusted : true , type : 'click' , target : targetEl , ... event } ; targetName ? this . globalEvents . emit ( globalEvent , clickEvent ) : targetEl . events . emit ( eventName , clickEvent ) ; } ) ; } createComment ( rendererArg , valueArg , commentElementArg ) { this . callBrowserRenderer ( 'createComment' , ... arguments ) ; } createElement ( rendererArg , nameArg , namespaceArg , elementArg ) { this . callBrowserRenderer ( 'createElement' , ... arguments ) ; } createRenderer ( hostElementArg , typeArg , rendererArg ) { this . callBrowserRenderer ( 'createRenderer' , ... arguments ) ; } createText ( rendererArg , valueArg , textElementArg ) { this . callBrowserRenderer ( 'createText' , ... arguments ) ; } destroy ( rendererArg ) { this . callBrowserRenderer ( 'destroy' , ... arguments ) ; } destroyNode ( rendererArg , nodeArg ) { this . callBrowserRenderer ( 'destroyNode' , ... arguments ) ; } insertBefore ( rendererArg , parentArg , newChildArg , refChildArg ) { this . callBrowserRenderer ( 'insertBefore' , ... arguments ) ; } listen ( rendererArg , targetElArg , targetNameArg , eventNameArg , listenIdArg ) { this . callBrowserRenderer ( 'listen' , ... arguments ) ; } nextSibling ( rendererArg , nodeArg , elementArg ) { this . callBrowserRenderer ( 'nextSibling' , ... arguments ) ; } parentNode ( rendererArg , nodeArg , elementArg ) { this . callBrowserRenderer ( 'parentNode' , ... arguments ) ; } removeAttribute ( rendererArg , elArg , nameArg , namespaceArg ) { this . callBrowserRenderer ( 'removeAttribute' , ... arguments ) ; } removeChild ( rendererArg , parentArg , oldChildArg , isHostElementArg ) { this . callBrowserRenderer ( 'removeChild' , ... arguments ) ; } removeClass ( rendererArg , elArg , nameArg ) { this . callBrowserRenderer ( 'removeClass' , ... arguments ) ; } removeStyle ( rendererArg , elArg , styleArg , flagsArg ) { this . callBrowserRenderer ( 'removeStyle' , ... arguments ) ; } selectRootElement ( rendererArg , selectorOrNodeArg , preserveContentArg , rootElementArg ) { this . callBrowserRenderer ( 'selectRootElement' , ... arguments ) ; } setAttribute ( rendererArg , elArg , nameArg , valueArg , namespaceArg ) { this . callBrowserRenderer ( 'setAttribute' , ... arguments ) ; } setProperty ( rendererArg , elArg , nameArg , valueArg ) { this . callBrowserRenderer ( 'setProperty' , ... arguments ) ; } setStyle ( rendererArg , elArg , styleArg , valueArg , flagsArg ) { this . callBrowserRenderer ( 'setStyle' , ... arguments ) ; } setValue ( rendererArg , nodeArg , valueArg ) { this . callBrowserRenderer ( 'setValue' , ... arguments ) ; } unlisten ( rendererArg , listenIdArg ) { this . callBrowserRenderer ( 'unlisten' , ... arguments ) ; } private callBrowserRenderer ( method , ... fnArgs ) { const payload = fnArgs . map ( arg => this . serializer . serialize ( arg . value , arg . type ) ) ; this . bus . sendCommand ( command ( 'renderer' , method , payload ) ) ; } private deserialize ( ... fnArgs ) { return fnArgs . map ( arg => this . serializer . deserialize ( arg . value , arg . type ) ) as [ Renderer2 , ... any [ ] ] ; } }