UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

1 lines 10.7 kB
{"version":3,"sources":["dynamic_component_loader.js"],"names":[],"mappings":"AAAA;AAAA,KAAO,EAAC,GAAE;AAAG,SAAO;AAAG,WAAS;AAAG,gBAAc,CAAC,KAAO,cAAY,CAAA;AACrE,KAAO,EAAC,QAAO,CAAC,KAAO,aAAW,CAAC;AACnC,KAAO,EAAC,uBAAsB,CAAC,KAAO,8BAA4B,CAAC;AACnE,KAAO,EAAC,IAAG;AAAG,cAAY;AAAG,UAAQ;AAAG,UAAQ,CAAC,KAAO,2BAAyB,CAAC;AAClF,KAAO,EAAC,OAAM,CAAC,KAAO,4BAA0B,CAAC;AACjD,KAAO,EAAC,SAAQ,CAAC,KAAO,4CAA0C,CAAC;AACnE,KAAO,EAAC,WAAU,CAAC,KAAO,0CAAwC,CAAC;AACnE,KAAO,EAAC,eAAc,CAAC,KAAO,2CAAyC,CAAC;AACxE,KAAO,EAAC,UAAS;AAAG,iBAAe,CAAC,KAAO,qBAAmB,CAAC;AAC/D,KAAO,EAAC,OAAM,CAAC,KAAO,SAAO,CAAC;AAK9B,KAAO,MAAM,aAAW;AAMtB,YAAU,CAAE,QAAO,AAAW,CAAG,CAAA,QAAO,AAAI,CAAG,CAAA,aAAY,AAAQ,CAAG,CAAA,OAAM,AAAS,CAAE;AApBzF,SAAK,cAAc,UAoBI,WAAS,WApBhC,CAAA,MAAK,KAAgB,oBAoB0C,QAAM,UAAW,SAAO,CApBjD,CAAA;AAqBlC,OAAG,SAAS,EAAI,SAAO,CAAC;AACxB,OAAG,SAAS,EAAI,SAAO,CAAC;AACxB,OAAG,cAAc,EAAI,cAAY,CAAC;AAClC,OAAG,SAAS,EAAI,QAAM,CAAC;EACzB;AAAA,AAEA,IAAI,SAAO,EAAI;AACb,SAAO,CAAA,IAAG,SAAS,SAAS,CAAC;EAC/B;AAAA,AAEA,IAAI,SAAO,EAAI;AACb,SAAO,CAAA,IAAG,SAAS,SAAS,CAAC;E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ACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YAmFC,IAAG,IAA2B,UAAS,IApFlE,MAAK,KAAgB,QAqFU,QAAO,GApFW;EAAC,CAAC,CAAC,CAAC;AADrD,KAAK,eAAe,AAAC,2EACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YA2GQ,IAAG,IAAY,UAAS,IAAY,QAAO,GA3G5B;EAAC,CAAC,CAAC,CAAC;AADrD,KAAK,eAAe,AAAC,uEACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YA4HI,IAAG,GA5HgB;EAAC,CAAC,CAAC,CAAC;AAmIrD","file":"angular2/src/core/compiler/dynamic_component_loader.es6","sourcesContent":["import {Key, Injector, Injectable, ResolvedBinding} from 'angular2/di'\nimport {Compiler} from './compiler';\nimport {DirectiveMetadataReader} from './directive_metadata_reader';\nimport {Type, BaseException, stringify, isPresent} from 'angular2/src/facade/lang';\nimport {Promise} from 'angular2/src/facade/async';\nimport {Component} from 'angular2/src/core/annotations/annotations';\nimport {ViewFactory} from 'angular2/src/core/compiler/view_factory';\nimport {AppViewHydrator} from 'angular2/src/core/compiler/view_hydrator';\nimport {ElementRef, DirectiveBinding} from './element_injector';\nimport {AppView} from './view';\n\n/**\n * @exportedAs angular2/view\n */\nexport class ComponentRef {\n location:ElementRef;\n instance:any;\n componentView:AppView;\n _dispose:Function;\n\n constructor(location:ElementRef, instance:any, componentView:AppView, dispose:Function){\n this.location = location;\n this.instance = instance;\n this.componentView = componentView;\n this._dispose = dispose;\n }\n\n get injector() {\n return this.location.injector;\n }\n\n get hostView() {\n return this.location.hostView;\n }\n\n dispose() {\n this._dispose();\n }\n}\n\n/**\n * Service for dynamically loading a Component into an arbitrary position in the internal Angular\n * application tree.\n *\n * @exportedAs angular2/view\n */\n@Injectable()\nexport class DynamicComponentLoader {\n _compiler:Compiler;\n _viewFactory:ViewFactory;\n _viewHydrator:AppViewHydrator;\n _directiveMetadataReader:DirectiveMetadataReader;\n\n constructor(compiler:Compiler, directiveMetadataReader:DirectiveMetadataReader,\n viewFactory:ViewFactory, viewHydrator:AppViewHydrator) {\n this._compiler = compiler;\n this._directiveMetadataReader = directiveMetadataReader;\n this._viewFactory = viewFactory;\n this._viewHydrator = viewHydrator;\n }\n\n /**\n * Loads a component into the location given by the provided ElementRef. The loaded component\n * receives injection as if it in the place of the provided ElementRef.\n */\n loadIntoExistingLocation(type:Type, location:ElementRef, injector:Injector = null):Promise<ComponentRef> {\n this._assertTypeIsComponent(type);\n var annotation = this._directiveMetadataReader.read(type).annotation;\n var componentBinding = DirectiveBinding.createFromType(type, annotation);\n\n return this._compiler.compile(type).then(componentProtoView => {\n var componentView = this._viewFactory.getView(componentProtoView);\n this._viewHydrator.hydrateDynamicComponentView(\n location, componentView, componentBinding, injector);\n\n var dispose = () => {throw new BaseException(\"Not implemented\");};\n return new ComponentRef(location, location.elementInjector.getDynamicallyLoadedComponent(), componentView, dispose);\n });\n }\n\n /**\n * Loads a component in the element specified by elementOrSelector. The loaded component receives\n * injection normally as a hosted view.\n */\n loadIntoNewLocation(type:Type, parentComponentLocation:ElementRef, elementOrSelector:any,\n injector:Injector = null):Promise<ComponentRef> {\n this._assertTypeIsComponent(type);\n\n return this._compiler.compileInHost(type).then(hostProtoView => {\n var hostView = this._viewFactory.getView(hostProtoView);\n this._viewHydrator.hydrateInPlaceHostView(\n parentComponentLocation, elementOrSelector, hostView, injector\n );\n\n var newLocation = hostView.elementInjectors[0].getElementRef();\n var component = hostView.elementInjectors[0].getComponent();\n var dispose = () => {\n this._viewHydrator.dehydrateInPlaceHostView(parentComponentLocation, hostView);\n this._viewFactory.returnView(hostView);\n };\n return new ComponentRef(newLocation, component, hostView.componentChildViews[0], dispose);\n });\n }\n\n /**\n * Loads a component next to the provided ElementRef. The loaded component receives\n * injection normally as a hosted view.\n */\n loadNextToExistingLocation(type:Type, location:ElementRef, injector:Injector = null):Promise<ComponentRef> {\n this._assertTypeIsComponent(type);\n\n return this._compiler.compileInHost(type).then(hostProtoView => {\n var hostView = location.viewContainer.create(-1, hostProtoView, injector);\n\n var newLocation = hostView.elementInjectors[0].getElementRef();\n var component = hostView.elementInjectors[0].getComponent();\n var dispose = () => {\n var index = location.viewContainer.indexOf(hostView);\n location.viewContainer.remove(index);\n };\n return new ComponentRef(newLocation, component, hostView.componentChildViews[0], dispose);\n });\n }\n\n /** Asserts that the type being dynamically instantiated is a Component. */\n _assertTypeIsComponent(type:Type) {\n var annotation = this._directiveMetadataReader.read(type).annotation;\n if (!(annotation instanceof Component)) {\n throw new BaseException(`Could not load '${stringify(type)}' because it is not a component.`);\n }\n }\n}\n"]}