import { Injectable , NgZone } from '@angular/core' ; import { AnimationEngineAdapter , AnimationEngineMethods , command , DomEventArg , FnArg , MessageBus , PrimitiveArg , Serializer , StoreObjectArg } from '../shared' ; @ Injectable ( ) export class ServerAnimationEngineAdapter extends AnimationEngineAdapter { constructor ( private bus , private serializer , private ngZone ) { super ( ) ; } destroy ( namespaceIdArg , contextArg ) { this . callBrowserAnimationEngine ( 'destroy' , ... arguments ) ; } disableAnimations ( elementArg , disableArg ) { this . callBrowserAnimationEngine ( 'disableAnimations' , ... arguments ) ; } flush ( microtaskIdArg ) { this . callBrowserAnimationEngine ( 'flush' , ... arguments ) ; } event ( elementArg , eventNameArg , eventArg ) { const [ element , eventName , event ] = this . deserialize ( ... arguments ) ; this . ngZone . run ( ( ) => { element . events . emit ( eventName , event ) ; } ) ; } listen ( namespaceIdArg , elementArg , eventNameArg , eventPhaseArg , listenIdArg ) { this . callBrowserAnimationEngine ( 'listen' , ... arguments ) ; } onInsert ( namespaceIdArg , elementArg , parentArg , insertBeforeArg ) { this . callBrowserAnimationEngine ( 'onInsert' , ... arguments ) ; } onRemove ( namespaceIdArg , elementArg , contextArg , isHostElementArg ) { this . callBrowserAnimationEngine ( 'onRemove' , ... arguments ) ; } onRemovalComplete ( elementArg , contextArg ) { this . callBrowserAnimationEngine ( 'onRemovalComplete' , ... arguments ) ; } process ( namespaceIdArg , elementArg , propertyArg , valueArg ) { this . callBrowserAnimationEngine ( 'process' , ... arguments ) ; } register ( namespaceIdArg , hostElementArg ) { this . callBrowserAnimationEngine ( 'register' , ... arguments ) ; } registerTrigger ( componentIdArg , namespaceIdArg , hostElementArg , nameArg , metadataArg ) { this . callBrowserAnimationEngine ( 'registerTrigger' , ... arguments ) ; } unlisten ( listenIdArg ) { this . callBrowserAnimationEngine ( 'unlisten' , ... arguments ) ; } private callBrowserAnimationEngine ( method , ... fnArgs ) { const payload = fnArgs . map ( arg => this . serializer . serialize ( arg . value , arg . type ) ) ; this . bus . sendCommand ( command ( 'animation-engine' , method , payload ) ) ; } private deserialize ( ... fnArgs ) { return fnArgs . map ( arg => this . serializer . deserialize ( arg . value , arg . type ) ) as [ ... any [ ] ] ; } }