本文整理汇总了TypeScript中angular2/src/facade/async.PromiseWrapper.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PromiseWrapper.all方法的具体用法?TypeScript PromiseWrapper.all怎么用?TypeScript PromiseWrapper.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/src/facade/async.PromiseWrapper
的用法示例。
在下文中一共展示了PromiseWrapper.all方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _inlineImports
_inlineImports(cssText: string, baseUrl: string,
inlinedUrls: List<string>): SyncAsyncResult<string> {
var partIndex = 0;
var parts = StringWrapper.split(cssText, _importRe);
if (parts.length === 1) {
// no @import rule found, return the original css
return new SyncAsyncResult(cssText, null);
}
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 (isPresent(url)) {
url = this._urlResolver.resolve(baseUrl, url);
}
var mediaQuery = _extractMediaQuery(rule);
var promise;
if (isBlank(url)) {
promise = PromiseWrapper.resolve(`/* Invalid import rule: "@import ${rule};" */`);
} else if (ListWrapper.contains(inlinedUrls, url)) {
// The current import rule has already been inlined, return the prefix only
// Importing again might cause a circular dependency
promise = PromiseWrapper.resolve(prefix);
} else {
ListWrapper.push(inlinedUrls, url);
promise = PromiseWrapper.then(this._xhr.get(url), (rawCss) => {
// resolve nested @import rules
var inlinedCss = this._inlineImports(rawCss, url, inlinedUrls);
if (isPresent(inlinedCss.asyncResult)) {
// wait until nested @import are inlined
return inlinedCss.asyncResult.then(
(css) => {return prefix + this._transformImportedCss(css, mediaQuery, url) + '\n'});
} else {
// there are no nested @import, return the css
return prefix + this._transformImportedCss(inlinedCss.syncResult, mediaQuery, url) +
'\n';
}
}, (error) => `/* failed to import ${url} */\n`);
}
ListWrapper.push(promises, promise);
partIndex += 2;
}
return new SyncAsyncResult(null, 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;
}));
}
示例2: expect
PromiseWrapper.all([injectorPromise1, injectorPromise2]).then((injectors) => {
var registry = injectors[0].get(TestabilityRegistry);
PromiseWrapper.all([injectors[0].asyncGet(Testability), injectors[1].asyncGet(Testability)]).then((testabilities) => {
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
async.done();
});
});
示例3: it
it('should support multiple calls to bootstrap', inject([AsyncTestCompleter], (async) => {
var injectorPromise1 = bootstrap(HelloRootCmp, testBindings);
var injectorPromise2 = bootstrap(HelloRootCmp2, testBindings);
PromiseWrapper.all([injectorPromise1, injectorPromise2]).then((injectors) => {
expect(injectors[0].get(appElementToken)).toHaveText('hello world!');
expect(injectors[1].get(appElementToken)).toHaveText('hello world, again!');
async.done();
});
}));
示例4: it
it("should create only one instance (async + async)", inject([AsyncTestCompleter], (async) => {
var injector = new Injector([bind(UserList).toAsyncFactory(fetchUsers)]);
var ul1 = injector.asyncGet(UserList);
var ul2 = injector.asyncGet(UserList);
PromiseWrapper.all([ul1, ul2]).then(function(uls) {
expect(uls[0]).toBe(uls[1]);
async.done();
});
}));
示例5: instantiate
instantiate(key) {
var binding = this.injector._getBinding(key);
if (isBlank(binding))
return _notFound;
this.injector._markAsConstructing(key);
var deps = this.injector._resolveDependencies(key, binding, true);
var depsPromise = PromiseWrapper.all(deps);
var promise = PromiseWrapper.then(depsPromise, null, (e) => this._errorHandler(key, e)).then((deps) => this._findOrCreate(key, binding, deps)).then((instance) => this._cacheInstance(key, instance));
this.injector._setInstance(key, new _Waiting(promise));
return promise;
}
示例6: compile
function compile(components: Type[]): Promise<any[]> {
return PromiseWrapper.all(components.map(normalizeComponent))
.then((normalizedCompWithViewDirMetas: NormalizedComponentWithViewDirectives[]) => {
var sourceModule = compiler.compileTemplatesCodeGen(normalizedCompWithViewDirMetas);
var sourceWithImports =
testableTemplateModule(sourceModule,
normalizedCompWithViewDirMetas[0].component)
.getSourceWithImports();
return evalModule(sourceWithImports.source, sourceWithImports.imports, null);
});
}
示例7: normalizeComponent
function normalizeComponent(
component: Type): Promise<NormalizedComponentWithViewDirectives> {
var compAndViewDirMetas = [runtimeMetadataResolver.getMetadata(component)].concat(
runtimeMetadataResolver.getViewDirectivesMetadata(component));
return PromiseWrapper.all(compAndViewDirMetas.map(
meta => compiler.normalizeDirectiveMetadata(meta)))
.then((normalizedCompAndViewDirMetas: CompileDirectiveMetadata[]) =>
new NormalizedComponentWithViewDirectives(
normalizedCompAndViewDirMetas[0],
normalizedCompAndViewDirMetas.slice(1)));
}
示例8: inject
inject([AsyncTestCompleter, XHR], (async, xhr: MockXHR) => {
xhr.expect('package:angular2/test/compiler/compUrl.html', 'a');
PromiseWrapper.all([compile([CompWithTemplateUrl]), compile([CompWithTemplateUrl])])
.then((humanizedTemplates) => {
expect(humanizedTemplates[0]['commands'][1]['commands']).toEqual(['#text(a)']);
expect(humanizedTemplates[1]['commands'][1]['commands']).toEqual(['#text(a)']);
async.done();
});
xhr.flush();
}));
示例9: BaseException
pvPromise = this._compileNoRecurse(componentBinding, template, directives).then((protoView) => {
this._compilerCache.set(component, protoView);
MapWrapper.delete(this._compiling, component);
var nestedPVPromises = this._compileNestedComponents(protoView);
if (nestedPVPromises.length > 0) {
return PromiseWrapper.then(PromiseWrapper.all(nestedPVPromises), (_) => protoView, (e) => {
throw new BaseException(`${e} -> Failed to compile ${stringify(component)}`);
});
}
return protoView;
});
示例10: _compileTemplate
_compileTemplate(template, tplElement) {
var subTaskPromises = [];
var pipeline = new 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 PromiseWrapper.all(subTaskPromises).then((_) => protoView);
} else {
return PromiseWrapper.resolve(protoView);
}
}