load(viewDef) {
     var r = wtfStartTimeRange('ViewLoader#load()', stringify(viewDef.componentId));
     let tplAndStyles = [this._loadHtml(viewDef.template, viewDef.templateAbsUrl, viewDef.componentId)];
     if (isPresent(viewDef.styles)) {
         viewDef.styles.forEach((cssText) => {
             let textOrPromise = this._resolveAndInlineCssText(cssText, viewDef.templateAbsUrl);
             tplAndStyles.push(textOrPromise);
         });
     }
     if (isPresent(viewDef.styleAbsUrls)) {
         viewDef.styleAbsUrls.forEach(url => {
             let promise = this._loadText(url).then(cssText => this._resolveAndInlineCssText(cssText, viewDef.templateAbsUrl));
             tplAndStyles.push(promise);
         });
     }
     // Inline the styles from the @View annotation
     return PromiseWrapper.all(tplAndStyles)
         .then((res) => {
         let loadedTplAndStyles = res[0];
         let styles = ListWrapper.slice(res, 1);
         var templateAndStyles = new TemplateAndStyles(loadedTplAndStyles.template, loadedTplAndStyles.styles.concat(styles));
         wtfEndTimeRange(r);
         return templateAndStyles;
     });
 }
Example #2
0
 TemplateCompiler.prototype._compileComponentRuntime = function (cacheKey, compMeta, viewDirectives, compilingComponentCacheKeys) {
     var _this = this;
     var uniqViewDirectives = removeDuplicates(viewDirectives);
     var compiledTemplate = this._compiledTemplateCache.get(cacheKey);
     var done = this._compiledTemplateDone.get(cacheKey);
     if (lang_1.isBlank(compiledTemplate)) {
         var styles = [];
         var changeDetectorFactory;
         var commands = [];
         var templateId = lang_1.stringify(compMeta.type.runtime) + "Template" + this._nextTemplateId++;
         compiledTemplate = new template_commands_1.CompiledComponentTemplate(templateId, function (dispatcher) { return changeDetectorFactory(dispatcher); }, commands, styles);
         this._compiledTemplateCache.set(cacheKey, compiledTemplate);
         compilingComponentCacheKeys.add(cacheKey);
         done = async_1.PromiseWrapper
             .all([this._styleCompiler.compileComponentRuntime(compMeta.template)].concat(uniqViewDirectives.map(function (dirMeta) { return _this.normalizeDirectiveMetadata(dirMeta); })))
             .then(function (stylesAndNormalizedViewDirMetas) {
             var childPromises = [];
             var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
             var parsedTemplate = _this._templateParser.parse(compMeta.template.template, normalizedViewDirMetas, compMeta.type.name);
             var changeDetectorFactories = _this._cdCompiler.compileComponentRuntime(compMeta.type, compMeta.changeDetection, parsedTemplate);
             changeDetectorFactory = changeDetectorFactories[0];
             var tmpStyles = stylesAndNormalizedViewDirMetas[0];
             tmpStyles.forEach(function (style) { return styles.push(style); });
             var tmpCommands = _this._compileCommandsRuntime(compMeta, parsedTemplate, changeDetectorFactories, compilingComponentCacheKeys, childPromises);
             tmpCommands.forEach(function (cmd) { return commands.push(cmd); });
             return async_1.PromiseWrapper.all(childPromises);
         })
             .then(function (_) {
             collection_1.SetWrapper.delete(compilingComponentCacheKeys, cacheKey);
             return compiledTemplate;
         });
         this._compiledTemplateDone.set(cacheKey, done);
     }
     return compiledTemplate;
 };
 load(view) {
     let html;
     let fetchedStyles;
     // Load the HTML
     if (isPresent(view.template)) {
         html = PromiseWrapper.resolve(view.template);
     }
     else if (isPresent(view.templateAbsUrl)) {
         html = this._loadText(view.templateAbsUrl);
     }
     else {
         throw new BaseException('View should have either the templateUrl or template property set');
     }
     // Load the styles
     if (isPresent(view.styleAbsUrls) && view.styleAbsUrls.length > 0) {
         fetchedStyles = ListWrapper.map(view.styleAbsUrls, url => this._loadText(url));
     }
     else {
         fetchedStyles = [];
     }
     // Inline the styles and return a template element
     return PromiseWrapper.all(ListWrapper.concat([html], fetchedStyles))
         .then((res) => {
         let html = res[0];
         let fetchedStyles = ListWrapper.slice(res, 1);
         html = _createStyleTags(view.styles) + _createStyleTags(fetchedStyles) + html;
         return DOM.createTemplate(html);
     });
 }
 _compileComponentRuntime(cacheKey, compMeta, viewDirectives, pipes, compilingComponentsPath) {
     let uniqViewDirectives = removeDuplicates(viewDirectives);
     let uniqViewPipes = removeDuplicates(pipes);
     var compiledTemplate = this._compiledTemplateCache.get(cacheKey);
     var done = this._compiledTemplateDone.get(cacheKey);
     if (isBlank(compiledTemplate)) {
         compiledTemplate = new CompiledTemplate();
         this._compiledTemplateCache.set(cacheKey, compiledTemplate);
         done = PromiseWrapper
             .all([this._styleCompiler.compileComponentRuntime(compMeta.template)].concat(uniqViewDirectives.map(dirMeta => this.normalizeDirectiveMetadata(dirMeta))))
             .then((stylesAndNormalizedViewDirMetas) => {
             var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
             var styles = stylesAndNormalizedViewDirMetas[0];
             var parsedTemplate = this._templateParser.parse(compMeta.template.template, normalizedViewDirMetas, uniqViewPipes, compMeta.type.name);
             var childPromises = [];
             var usedDirectives = DirectiveCollector.findUsedDirectives(parsedTemplate);
             usedDirectives.components.forEach(component => this._compileNestedComponentRuntime(component, compilingComponentsPath, childPromises));
             return PromiseWrapper.all(childPromises)
                 .then((_) => {
                 var filteredPipes = filterPipes(parsedTemplate, uniqViewPipes);
                 compiledTemplate.init(this._createViewFactoryRuntime(compMeta, parsedTemplate, usedDirectives.directives, styles, filteredPipes));
                 return compiledTemplate;
             });
         });
         this._compiledTemplateDone.set(cacheKey, done);
     }
     return compiledTemplate;
 }
 _compileComponentRuntime(cacheKey, compMeta, viewDirectives, compilingComponentCacheKeys) {
     let uniqViewDirectives = removeDuplicates(viewDirectives);
     var compiledTemplate = this._compiledTemplateCache.get(cacheKey);
     var done = this._compiledTemplateDone.get(cacheKey);
     if (isBlank(compiledTemplate)) {
         var styles = [];
         var changeDetectorFactory;
         var commands = [];
         var templateId = `${stringify(compMeta.type.runtime)}Template${this._nextTemplateId++}`;
         compiledTemplate = new CompiledComponentTemplate(templateId, (dispatcher) => changeDetectorFactory(dispatcher), commands, styles);
         this._compiledTemplateCache.set(cacheKey, compiledTemplate);
         compilingComponentCacheKeys.add(cacheKey);
         done = PromiseWrapper
             .all([this._styleCompiler.compileComponentRuntime(compMeta.template)].concat(uniqViewDirectives.map(dirMeta => this.normalizeDirectiveMetadata(dirMeta))))
             .then((stylesAndNormalizedViewDirMetas) => {
             var childPromises = [];
             var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
             var parsedTemplate = this._templateParser.parse(compMeta.template.template, normalizedViewDirMetas, compMeta.type.name);
             var changeDetectorFactories = this._cdCompiler.compileComponentRuntime(compMeta.type, compMeta.changeDetection, parsedTemplate);
             changeDetectorFactory = changeDetectorFactories[0];
             var tmpStyles = stylesAndNormalizedViewDirMetas[0];
             tmpStyles.forEach(style => styles.push(style));
             var tmpCommands = this._compileCommandsRuntime(compMeta, parsedTemplate, changeDetectorFactories, compilingComponentCacheKeys, childPromises);
             tmpCommands.forEach(cmd => commands.push(cmd));
             return PromiseWrapper.all(childPromises);
         })
             .then((_) => {
             SetWrapper.delete(compilingComponentCacheKeys, cacheKey);
             return compiledTemplate;
         });
         this._compiledTemplateDone.set(cacheKey, done);
     }
     return compiledTemplate;
 }
Example #6
0
 Compiler.prototype._compileNestedProtoViews = function (componentBinding, renderPv, directives) {
     var _this = this;
     var protoViews = this._protoViewFactory.createAppProtoViews(componentBinding, renderPv, directives);
     var protoView = protoViews[0];
     // TODO(tbosch): we should be caching host protoViews as well!
     // -> need a separate cache for this...
     if (renderPv.type === renderApi.ViewType.COMPONENT && lang_1.isPresent(componentBinding)) {
         // Populate the cache before compiling the nested components,
         // so that components can reference themselves in their template.
         var component = componentBinding.key.token;
         this._compilerCache.set(component, protoView);
         collection_1.MapWrapper.delete(this._compiling, component);
     }
     var nestedPVPromises = [];
     collection_1.ListWrapper.forEach(this._collectComponentElementBinders(protoViews), function (elementBinder) {
         var nestedComponent = elementBinder.componentDirective;
         var elementBinderDone = function (nestedPv) { elementBinder.nestedProtoView = nestedPv; };
         var nestedCall = _this._compile(nestedComponent);
         if (lang_1.isPromise(nestedCall)) {
             collection_1.ListWrapper.push(nestedPVPromises, nestedCall.then(elementBinderDone));
         }
         else if (lang_1.isPresent(nestedCall)) {
             elementBinderDone(nestedCall);
         }
     });
     if (nestedPVPromises.length > 0) {
         return async_1.PromiseWrapper.all(nestedPVPromises).then(function (_) { return protoView; });
     }
     else {
         return protoView;
     }
 };
Example #7
0
 RuntimeCompiler.prototype._resolveStylesCompileResult = function (sourceUrl, result) {
     var _this = this;
     var promises = result.dependencies.map(function (dep) { return _this._loadStylesheetDep(dep); });
     return async_1.PromiseWrapper.all(promises)
         .then(function (cssTexts) {
         var nestedCompileResultPromises = [];
         for (var i = 0; i < result.dependencies.length; i++) {
             var dep = result.dependencies[i];
             var cssText = cssTexts[i];
             var nestedCompileResult = _this._styleCompiler.compileStylesheet(dep.sourceUrl, cssText, dep.isShimmed);
             nestedCompileResultPromises.push(_this._resolveStylesCompileResult(dep.sourceUrl, nestedCompileResult));
         }
         return async_1.PromiseWrapper.all(nestedCompileResultPromises);
     })
         .then(function (nestedStylesArr) {
         for (var i = 0; i < result.dependencies.length; i++) {
             var dep = result.dependencies[i];
             dep.valuePlaceholder.runtime = nestedStylesArr[i];
             dep.valuePlaceholder.name = "importedStyles" + i;
         }
         if (lang_1.IS_DART || !_this._genConfig.useJit) {
             return output_interpreter_1.interpretStatements(result.statements, result.stylesVar, new interpretive_view_1.InterpretiveAppViewInstanceFactory());
         }
         else {
             return output_jit_1.jitStatements(sourceUrl + ".css.js", result.statements, result.stylesVar);
         }
     });
 };
Example #8
0
 TemplateLoader.prototype.load = function (view) {
     var _this = this;
     var html;
     var fetchedStyles;
     // Load the HTML
     if (lang_1.isPresent(view.template)) {
         html = async_1.PromiseWrapper.resolve(view.template);
     }
     else if (lang_1.isPresent(view.templateAbsUrl)) {
         html = this._loadText(view.templateAbsUrl);
     }
     else {
         throw new lang_1.BaseException('View should have either the templateUrl or template property set');
     }
     // Load the styles
     if (lang_1.isPresent(view.styleAbsUrls) && view.styleAbsUrls.length > 0) {
         fetchedStyles = collection_1.ListWrapper.map(view.styleAbsUrls, function (url) { return _this._loadText(url); });
     }
     else {
         fetchedStyles = [];
     }
     // Inline the styles and return a template element
     return async_1.PromiseWrapper.all(collection_1.ListWrapper.concat([html], fetchedStyles))
         .then(function (res) {
         var html = res[0];
         var fetchedStyles = collection_1.ListWrapper.slice(res, 1);
         html = _createStyleTags(view.styles) + _createStyleTags(fetchedStyles) + html;
         return dom_adapter_1.DOM.createTemplate(html);
     });
 };
 return html.then(html => {
     var tplEl = DOM.createTemplate(html);
     // Replace $baseUrl with the base url for the template
     if (isPresent(templateAbsUrl) && templateAbsUrl.indexOf("/") >= 0) {
         let baseUrl = templateAbsUrl.substring(0, templateAbsUrl.lastIndexOf("/"));
         this._substituteBaseUrl(DOM.content(tplEl), baseUrl);
     }
     let styleEls = DOM.querySelectorAll(DOM.content(tplEl), 'STYLE');
     let unresolvedStyles = [];
     for (let i = 0; i < styleEls.length; i++) {
         var styleEl = styleEls[i];
         unresolvedStyles.push(DOM.getText(styleEl));
         DOM.remove(styleEl);
     }
     let syncStyles = [];
     let asyncStyles = [];
     // Inline the style tags from the html
     for (let i = 0; i < styleEls.length; i++) {
         let styleEl = styleEls[i];
         let resolvedStyled = this._resolveAndInlineCssText(DOM.getText(styleEl), templateAbsUrl);
         if (isPromise(resolvedStyled)) {
             asyncStyles.push(resolvedStyled);
         }
         else {
             syncStyles.push(resolvedStyled);
         }
     }
     if (asyncStyles.length === 0) {
         return PromiseWrapper.resolve(new TemplateAndStyles(DOM.getInnerHTML(tplEl), syncStyles));
     }
     else {
         return PromiseWrapper.all(asyncStyles)
             .then(loadedStyles => new TemplateAndStyles(DOM.getInnerHTML(tplEl), syncStyles.concat(loadedStyles)));
     }
 });
 _completeAuxiliaryRouteMatches(instruction, parentComponent) {
     if (isBlank(instruction)) {
         return _resolveToNull;
     }
     var componentRecognizer = this._rules.get(parentComponent);
     var auxInstructions = {};
     var promises = instruction.auxUrls.map((auxSegment) => {
         var match = componentRecognizer.recognizeAuxiliary(auxSegment);
         if (isBlank(match)) {
             return _resolveToNull;
         }
         return this._completePrimaryRouteMatch(match).then((auxInstruction) => {
             if (isPresent(auxInstruction)) {
                 return this._completeAuxiliaryRouteMatches(auxInstruction, parentComponent)
                     .then((finishedAuxRoute) => {
                     auxInstructions[auxSegment.path] = finishedAuxRoute;
                 });
             }
         });
     });
     return PromiseWrapper.all(promises).then((_) => {
         if (isBlank(instruction.child)) {
             return new Instruction(instruction.component, null, auxInstructions);
         }
         return this._completeAuxiliaryRouteMatches(instruction.child, instruction.component.componentType)
             .then((completeChild) => {
             return new Instruction(instruction.component, completeChild, auxInstructions);
         });
     });
 }
Example #11
0
 StyleInliner.prototype._inlineImports = function (cssText, baseUrl, inlinedUrls) {
     var _this = this;
     var partIndex = 0;
     var parts = lang_1.StringWrapper.split(cssText, _importRe);
     if (parts.length === 1) {
         // no @import rule found, return the original css
         return cssText;
     }
     var promises = [];
     while (partIndex < parts.length - 1) {
         // prefix is the content before the @import rule
         var prefix = parts[partIndex];
         // rule is the parameter of the @import rule
         var rule = parts[partIndex + 1];
         var url = _extractUrl(rule);
         if (lang_1.isPresent(url)) {
             url = this._urlResolver.resolve(baseUrl, url);
         }
         var mediaQuery = _extractMediaQuery(rule);
         var promise;
         if (lang_1.isBlank(url)) {
             promise = async_1.PromiseWrapper.resolve("/* Invalid import rule: \"@import " + rule + ";\" */");
         }
         else if (collection_1.ListWrapper.contains(inlinedUrls, url)) {
             // The current import rule has already been inlined, return the prefix only
             // Importing again might cause a circular dependency
             promise = async_1.PromiseWrapper.resolve(prefix);
         }
         else {
             collection_1.ListWrapper.push(inlinedUrls, url);
             promise = async_1.PromiseWrapper.then(this._xhr.get(url), function (rawCss) {
                 // resolve nested @import rules
                 var inlinedCss = _this._inlineImports(rawCss, url, inlinedUrls);
                 if (lang_1.isPromise(inlinedCss)) {
                     // wait until nested @import are inlined
                     return inlinedCss
                         .then(function (css) {
                         return prefix + _this._transformImportedCss(css, mediaQuery, url) +
                             '\n';
                     });
                 }
                 else {
                     // there are no nested @import, return the css
                     return prefix + _this._transformImportedCss(inlinedCss, mediaQuery, url) + '\n';
                 }
             }, function (error) { return ("/* failed to import " + url + " */\n"); });
         }
         collection_1.ListWrapper.push(promises, promise);
         partIndex += 2;
     }
     return async_1.PromiseWrapper.all(promises).then(function (cssParts) {
         var cssText = cssParts.join('');
         if (partIndex < parts.length) {
             // append then content located after the last @import rule
             cssText += parts[partIndex];
         }
         return cssText;
     });
 };
 async_1.PromiseWrapper.all([injectorPromise1, injectorPromise2]).then(function (injectors) {
     var registry = injectors[0].get(testability_1.TestabilityRegistry);
     async_1.PromiseWrapper.all([injectors[0].asyncGet(testability_1.Testability), injectors[1].asyncGet(testability_1.Testability)]).then(function (testabilities) {
         test_lib_1.expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
         test_lib_1.expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
         async.done();
     });
 });
Example #13
0
     .then(function (stylesAndNormalizedViewDirMetas) {
     var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
     var styles = stylesAndNormalizedViewDirMetas[0];
     var parsedTemplate = _this._templateParser.parse(compMeta, compMeta.template.template, normalizedViewDirMetas, pipes, compMeta.type.name);
     var childPromises = [];
     compiledTemplate.init(_this._compileComponent(compMeta, parsedTemplate, styles, pipes, compilingComponentsPath, childPromises));
     return async_1.PromiseWrapper.all(childPromises).then(function (_) { return compiledTemplate; });
 });
Example #14
0
 test_lib_1.it("should create only one instance (async + async)", test_lib_1.inject([test_lib_1.AsyncTestCompleter], function (async) {
     var injector = new di_1.Injector([di_1.bind(UserList).toAsyncFactory(fetchUsers)]);
     var ul1 = injector.asyncGet(UserList);
     var ul2 = injector.asyncGet(UserList);
     async_1.PromiseWrapper.all([ul1, ul2]).then(function (uls) {
         test_lib_1.expect(uls[0]).toBe(uls[1]);
         async.done();
     });
 }));
 test_lib_1.it('should support multiple calls to bootstrap', test_lib_1.inject([test_lib_1.AsyncTestCompleter], function (async) {
     var injectorPromise1 = application_1.bootstrap(HelloRootCmp, testBindings);
     var injectorPromise2 = application_1.bootstrap(HelloRootCmp2, testBindings);
     async_1.PromiseWrapper.all([injectorPromise1, injectorPromise2]).then(function (injectors) {
         test_lib_1.expect(injectors[0].get(application_tokens_1.appElementToken)).toHaveText('hello world!');
         test_lib_1.expect(injectors[1].get(application_tokens_1.appElementToken)).toHaveText('hello world, again!');
         async.done();
     });
 }));
Example #16
0
     .then(function (cssTexts) {
     var nestedCompileResultPromises = [];
     for (var i = 0; i < result.dependencies.length; i++) {
         var dep = result.dependencies[i];
         var cssText = cssTexts[i];
         var nestedCompileResult = _this._styleCompiler.compileStylesheet(dep.sourceUrl, cssText, dep.isShimmed);
         nestedCompileResultPromises.push(_this._resolveStylesCompileResult(dep.sourceUrl, nestedCompileResult));
     }
     return async_1.PromiseWrapper.all(nestedCompileResultPromises);
 })
 _recognizePrimaryRoute(parsedUrl, parentComponent) {
     var componentRecognizer = this._rules.get(parentComponent);
     if (isBlank(componentRecognizer)) {
         return PromiseWrapper.resolve(null);
     }
     // Matches some beginning part of the given URL
     var possibleMatches = componentRecognizer.recognize(parsedUrl);
     var matchPromises = ListWrapper.map(possibleMatches, (candidate) => this._completePrimaryRouteMatch(candidate));
     return PromiseWrapper.all(matchPromises).then(mostSpecific);
 }
 _compileTemplate(viewDef, tplElement, protoViewType) {
     var subTaskPromises = [];
     var pipeline = new CompilePipeline(this._stepFactory.createSteps(viewDef, subTaskPromises));
     var compileElements = pipeline.process(tplElement, protoViewType, viewDef.componentId);
     var protoView = compileElements[0].inheritedProtoView.build(this._propertySetterFactory);
     if (subTaskPromises.length > 0) {
         return PromiseWrapper.all(subTaskPromises).then((_) => protoView);
     }
     else {
         return PromiseWrapper.resolve(protoView);
     }
 }
     .then((stylesAndNormalizedViewDirMetas) => {
     var childPromises = [];
     var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
     var parsedTemplate = this._templateParser.parse(compMeta.template.template, normalizedViewDirMetas, compMeta.type.name);
     var changeDetectorFactories = this._cdCompiler.compileComponentRuntime(compMeta.type, compMeta.changeDetection, parsedTemplate);
     changeDetectorFactory = changeDetectorFactories[0];
     var tmpStyles = stylesAndNormalizedViewDirMetas[0];
     tmpStyles.forEach(style => styles.push(style));
     var tmpCommands = this._compileCommandsRuntime(compMeta, parsedTemplate, changeDetectorFactories, compilingComponentCacheKeys, childPromises);
     tmpCommands.forEach(cmd => commands.push(cmd));
     return PromiseWrapper.all(childPromises);
 })
 test_lib_1.it('should register each application with the testability registry', test_lib_1.inject([test_lib_1.AsyncTestCompleter], function (async) {
     var injectorPromise1 = application_1.bootstrap(HelloRootCmp, testBindings);
     var injectorPromise2 = application_1.bootstrap(HelloRootCmp2, testBindings);
     async_1.PromiseWrapper.all([injectorPromise1, injectorPromise2]).then(function (injectors) {
         var registry = injectors[0].get(testability_1.TestabilityRegistry);
         async_1.PromiseWrapper.all([injectors[0].asyncGet(testability_1.Testability), injectors[1].asyncGet(testability_1.Testability)]).then(function (testabilities) {
             test_lib_1.expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
             test_lib_1.expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
             async.done();
         });
     });
 }));
Example #21
0
 Compiler.prototype._compileTemplate = function (template, tplElement) {
     var subTaskPromises = [];
     var pipeline = new compile_pipeline_1.CompilePipeline(this._stepFactory.createSteps(template, subTaskPromises));
     var compileElements;
     compileElements = pipeline.process(tplElement, template.componentId);
     var protoView = compileElements[0].inheritedProtoView.build();
     if (subTaskPromises.length > 0) {
         return async_1.PromiseWrapper.all(subTaskPromises).then(function (_) { return protoView; });
     }
     else {
         return async_1.PromiseWrapper.resolve(protoView);
     }
 };
Example #22
0
 return instruction.resolveComponent().then(function (_) {
     var unsettledInstructions = [];
     if (lang_1.isPresent(instruction.component)) {
         instruction.component.reuse = false;
     }
     if (lang_1.isPresent(instruction.child)) {
         unsettledInstructions.push(_this._settleInstruction(instruction.child));
     }
     collection_1.StringMapWrapper.forEach(instruction.auxInstruction, function (instruction, _) {
         unsettledInstructions.push(_this._settleInstruction(instruction));
     });
     return async_1.PromiseWrapper.all(unsettledInstructions);
 });
Example #23
0
 return instruction.resolveComponent().then((_) => {
     var unsettledInstructions = [];
     if (isPresent(instruction.component)) {
         instruction.component.reuse = false;
     }
     if (isPresent(instruction.child)) {
         unsettledInstructions.push(this._settleInstruction(instruction.child));
     }
     StringMapWrapper.forEach(instruction.auxInstruction, (instruction, _) => {
         unsettledInstructions.push(this._settleInstruction(instruction));
     });
     return PromiseWrapper.all(unsettledInstructions);
 });
Example #24
0
 Router.prototype._settleInstruction = function (instruction) {
     var _this = this;
     var unsettledInstructions = [];
     if (lang_1.isBlank(instruction.component.componentType)) {
         unsettledInstructions.push(instruction.component.resolveComponentType().then(function (type) { _this.registry.configFromComponent(type); }));
     }
     if (lang_1.isPresent(instruction.child)) {
         unsettledInstructions.push(this._settleInstruction(instruction.child));
     }
     collection_1.StringMapWrapper.forEach(instruction.auxInstruction, function (instruction, _) {
         unsettledInstructions.push(_this._settleInstruction(instruction));
     });
     return async_1.PromiseWrapper.all(unsettledInstructions);
 };
     .then((stylesAndNormalizedViewDirMetas) => {
     var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
     var styles = stylesAndNormalizedViewDirMetas[0];
     var parsedTemplate = this._templateParser.parse(compMeta.template.template, normalizedViewDirMetas, uniqViewPipes, compMeta.type.name);
     var childPromises = [];
     var usedDirectives = DirectiveCollector.findUsedDirectives(parsedTemplate);
     usedDirectives.components.forEach(component => this._compileNestedComponentRuntime(component, compilingComponentsPath, childPromises));
     return PromiseWrapper.all(childPromises)
         .then((_) => {
         var filteredPipes = filterPipes(parsedTemplate, uniqViewPipes);
         compiledTemplate.init(this._createViewFactoryRuntime(compMeta, parsedTemplate, usedDirectives.directives, styles, filteredPipes));
         return compiledTemplate;
     });
 });
 instantiate(key) {
     var binding = this._injector._getBinding(key);
     if (isBlank(binding))
         return _notFound;
     // add a marker so we can detect cyclic dependencies
     this._injector._markAsConstructing(key);
     var deps = this._injector._resolveDependencies(key, binding, true);
     var depsPromise = PromiseWrapper.all(deps);
     var promise = PromiseWrapper.then(depsPromise, null, (e, s) => this._errorHandler(key, e, s))
         .then(deps => this._findOrCreate(key, binding, deps))
         .then(instance => this._cacheInstance(key, instance));
     this._injector._setInstance(key, new _Waiting(promise));
     return promise;
 }
 _AsyncInjectorStrategy.prototype.instantiate = function (key) {
     var _this = this;
     var binding = this._injector._getBinding(key);
     if (lang_1.isBlank(binding))
         return _notFound;
     // add a marker so we can detect cyclic dependencies
     this._injector._markAsConstructing(key);
     var deps = this._injector._resolveDependencies(key, binding, true);
     var depsPromise = async_1.PromiseWrapper.all(deps);
     var promise = async_1.PromiseWrapper.then(depsPromise, null, function (e, s) { return _this._errorHandler(key, e, s); })
         .then(function (deps) { return _this._findOrCreate(key, binding, deps); })
         .then(function (instance) { return _this._cacheInstance(key, instance); });
     this._injector._setInstance(key, new _Waiting(promise));
     return promise;
 };
Example #28
0
 StyleInliner.prototype._inlineImports = function (cssText, baseUrl, inlinedUrls) {
     var _this = this;
     var partIndex = 0;
     var parts = lang_1.StringWrapper.split(cssText, _importRe);
     if (parts.length === 1) {
         return cssText;
     }
     var promises = [];
     while (partIndex < parts.length - 1) {
         var prefix = parts[partIndex];
         var rule = parts[partIndex + 1];
         var url = _extractUrl(rule);
         if (lang_1.isPresent(url)) {
             url = this._urlResolver.resolve(baseUrl, url);
         }
         var mediaQuery = _extractMediaQuery(rule);
         var promise;
         if (lang_1.isBlank(url)) {
             promise = async_1.PromiseWrapper.resolve("/* Invalid import rule: \"@import " + rule + ";\" */");
         }
         else if (collection_1.ListWrapper.contains(inlinedUrls, url)) {
             promise = async_1.PromiseWrapper.resolve(prefix);
         }
         else {
             collection_1.ListWrapper.push(inlinedUrls, url);
             promise = async_1.PromiseWrapper.then(this._xhr.get(url), function (css) {
                 css = _this._inlineImports(css, url, inlinedUrls);
                 if (async_1.PromiseWrapper.isPromise(css)) {
                     return css.then(function (css) {
                         return prefix + _this._transformImportedCss(css, mediaQuery, url) + '\n';
                     });
                 }
                 else {
                     return prefix + _this._transformImportedCss(css, mediaQuery, url) + '\n';
                 }
             }, function (error) { return ("/* failed to import " + url + " */\n"); });
         }
         collection_1.ListWrapper.push(promises, promise);
         partIndex += 2;
     }
     return async_1.PromiseWrapper.all(promises).then(function (cssParts) {
         var cssText = cssParts.join('');
         if (partIndex < parts.length) {
             cssText += parts[partIndex];
         }
         return cssText;
     });
 };
 /**
  * Recognizes all parent-child routes, but creates unresolved auxiliary routes
  */
 _recognize(parsedUrl, ancestorInstructions, _aux = false) {
     var parentComponent = ancestorInstructions.length > 0 ?
         ancestorInstructions[ancestorInstructions.length - 1].component.componentType :
         this._rootComponent;
     var componentRecognizer = this._rules.get(parentComponent);
     if (isBlank(componentRecognizer)) {
         return _resolveToNull;
     }
     // Matches some beginning part of the given URL
     var possibleMatches = _aux ? componentRecognizer.recognizeAuxiliary(parsedUrl) :
         componentRecognizer.recognize(parsedUrl);
     var matchPromises = possibleMatches.map((candidate) => candidate.then((candidate) => {
         if (candidate instanceof PathMatch) {
             var auxParentInstructions = ancestorInstructions.length > 0 ?
                 [ancestorInstructions[ancestorInstructions.length - 1]] :
                 [];
             var auxInstructions = this._auxRoutesToUnresolved(candidate.remainingAux, auxParentInstructions);
             var instruction = new ResolvedInstruction(candidate.instruction, null, auxInstructions);
             if (candidate.instruction.terminal) {
                 return instruction;
             }
             var newAncestorComponents = ancestorInstructions.concat([instruction]);
             return this._recognize(candidate.remaining, newAncestorComponents)
                 .then((childInstruction) => {
                 if (isBlank(childInstruction)) {
                     return null;
                 }
                 // redirect instructions are already absolute
                 if (childInstruction instanceof RedirectInstruction) {
                     return childInstruction;
                 }
                 instruction.child = childInstruction;
                 return instruction;
             });
         }
         if (candidate instanceof RedirectMatch) {
             var instruction = this.generate(candidate.redirectTo, ancestorInstructions);
             return new RedirectInstruction(instruction.component, instruction.child, instruction.auxInstruction);
         }
     }));
     if ((isBlank(parsedUrl) || parsedUrl.path == '') && possibleMatches.length == 0) {
         return PromiseWrapper.resolve(this.generateDefault(parentComponent));
     }
     return PromiseWrapper.all(matchPromises).then(mostSpecific);
 }
Example #30
0
function _runAppInitializers(injector) {
    var inits = injector.getOptional(application_tokens_1.APP_INITIALIZER);
    var promises = [];
    if (lang_1.isPresent(inits)) {
        inits.forEach(function (init) {
            var retVal = init();
            if (async_1.PromiseWrapper.isPromise(retVal)) {
                promises.push(retVal);
            }
        });
    }
    if (promises.length > 0) {
        return async_1.PromiseWrapper.all(promises);
    }
    else {
        return null;
    }
}