本文整理汇总了TypeScript中angular2/src/facade/collection.Map类的典型用法代码示例。如果您正苦于以下问题:TypeScript Map类的具体用法?TypeScript Map怎么用?TypeScript Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: coalesce
export function coalesce(records: ProtoRecord[]): ProtoRecord[] {
var res: List<ProtoRecord> = [];
var indexMap: Map<number, number> = new Map<number, number>();
for (var i = 0; i < records.length; ++i) {
var r = records[i];
var record = _replaceIndices(r, res.length + 1, indexMap);
var matchingRecord = _findMatching(record, res);
if (isPresent(matchingRecord) && record.lastInBinding) {
res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
matchingRecord.referencedBySelf = true;
} else if (isPresent(matchingRecord) && !record.lastInBinding) {
if (record.argumentToPureFunction) {
matchingRecord.argumentToPureFunction = true;
}
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
} else {
res.push(record);
indexMap.set(r.selfIndex, record.selfIndex);
}
}
return res;
}
示例2: create
static create({id, selector, compileChildren, events, host, properties, readAttributes, type,
callOnDestroy, callOnChange, callOnCheck, callOnInit, callOnAllChangesDone,
changeDetection, exportAs}: {
id?: string,
selector?: string,
compileChildren?: boolean,
events?: List<string>,
host?: Map<string, string>,
properties?: List<string>,
readAttributes?: List<string>,
type?: number,
callOnDestroy?: boolean,
callOnChange?: boolean,
callOnCheck?: boolean,
callOnInit?: boolean,
callOnAllChangesDone?: boolean,
changeDetection?: string,
exportAs?: string
}) {
let hostListeners = new Map();
let hostProperties = new Map();
let hostAttributes = new Map();
let hostActions = new Map();
if (isPresent(host)) {
MapWrapper.forEach(host, (value: string, key: string) => {
var matches = RegExpWrapper.firstMatch(hostRegExp, key);
if (isBlank(matches)) {
hostAttributes.set(key, value);
} else if (isPresent(matches[1])) {
hostProperties.set(matches[1], value);
} else if (isPresent(matches[2])) {
hostListeners.set(matches[2], value);
} else if (isPresent(matches[3])) {
hostActions.set(matches[3], value);
}
});
}
return new DirectiveMetadata({
id: id,
selector: selector,
compileChildren: compileChildren,
events: events,
hostListeners: hostListeners,
hostProperties: hostProperties,
hostAttributes: hostAttributes,
hostActions: hostActions,
properties: properties,
readAttributes: readAttributes,
type: type,
callOnDestroy: callOnDestroy,
callOnChange: callOnChange,
callOnCheck: callOnCheck,
callOnInit: callOnInit,
callOnAllChangesDone: callOnAllChangesDone,
changeDetection: changeDetection,
exportAs: exportAs
});
}
示例3: resolve
/**
* Returns the {@link View} for a component:
* - Set the {@link View} to the overridden view when it exists or fallback to the default
* `TemplateResolver`,
* see `setView`.
* - Override the directives, see `overrideViewDirective`.
* - Override the @View definition, see `setInlineTemplate`.
*
* @param component
* @returns {ViewDefinition}
*/
resolve(component: Type): View {
var view = this._viewCache.get(component);
if (isPresent(view)) return view;
view = this._views.get(component);
if (isBlank(view)) {
view = super.resolve(component);
}
var directives = view.directives;
var overrides = this._directiveOverrides.get(component);
if (isPresent(overrides) && isPresent(directives)) {
directives = ListWrapper.clone(view.directives);
MapWrapper.forEach(overrides, (to, from) => {
var srcIndex = directives.indexOf(from);
if (srcIndex == -1) {
throw new BaseException(
`Overriden directive ${stringify(from)} not found in the template of ${stringify(component)}`);
}
directives[srcIndex] = to;
});
view = new View(
{template: view.template, templateUrl: view.templateUrl, directives: directives});
}
var inlineTemplate = this._inlineTemplates.get(component);
if (isPresent(inlineTemplate)) {
view = new View({template: inlineTemplate, templateUrl: null, directives: view.directives});
}
this._viewCache.set(component, view);
return view;
}
示例4: config
/**
* Given a component and a configuration object, add the route to this registry
*/
config(parentComponent, config: StringMap<string, any>): void {
assertValidConfig(config);
var recognizer: RouteRecognizer = this._rules.get(parentComponent);
if (isBlank(recognizer)) {
recognizer = new RouteRecognizer();
this._rules.set(parentComponent, recognizer);
}
if (StringMapWrapper.contains(config, 'redirectTo')) {
recognizer.addRedirect(config['path'], config['redirectTo']);
return;
}
config = StringMapWrapper.merge(
config, {'component': normalizeComponentDeclaration(config['component'])});
var component = config['component'];
var terminal = recognizer.addConfig(config['path'], config, config['as']);
if (component['type'] == 'constructor') {
if (terminal) {
assertTerminalComponent(component['constructor'], config['path']);
} else {
this.configFromComponent(component['constructor']);
}
}
}
示例5: coalesce
export function coalesce(srcRecords: ProtoRecord[]): ProtoRecord[] {
let dstRecords = [];
let excludedIdxs = [];
let indexMap: Map<number, number> = new Map<number, number>();
let skipDepth = 0;
let skipSources: ProtoRecord[] = ListWrapper.createFixedSize(srcRecords.length);
for (let protoIndex = 0; protoIndex < srcRecords.length; protoIndex++) {
let skipRecord = skipSources[protoIndex];
if (isPresent(skipRecord)) {
skipDepth--;
skipRecord.fixedArgs[0] = dstRecords.length;
}
let src = srcRecords[protoIndex];
let dst = _cloneAndUpdateIndexes(src, dstRecords, indexMap);
if (dst.isSkipRecord()) {
dstRecords.push(dst);
skipDepth++;
skipSources[dst.fixedArgs[0]] = dst;
} else {
let record = _mayBeAddRecord(dst, dstRecords, excludedIdxs, skipDepth > 0);
indexMap.set(src.selfIndex, record.selfIndex);
}
}
return _optimizeSkips(dstRecords);
}
示例6: method
method(name: string): MethodFn {
if (this._methods.has(name)) {
return this._methods.get(name);
} else {
return this.reflectionCapabilities.method(name);
}
}
示例7: setter
setter(name: string): SetterFn {
if (this._setters.has(name)) {
return this._setters.get(name);
} else {
return this.reflectionCapabilities.setter(name);
}
}
示例8: isPresent
annotations(typeOrFunc: /*Type*/ any): List<any> {
if (this._injectableInfo.has(typeOrFunc)) {
var res = this._injectableInfo.get(typeOrFunc)._annotations;
return isPresent(res) ? res : [];
} else {
return this.reflectionCapabilities.annotations(typeOrFunc);
}
}
示例9: viewCreated
viewCreated(view: AppView) {
var viewId = _nextId++;
_allViewsById.set(viewId, view);
_allIdsByView.set(view, viewId);
for (var i = 0; i < view.elementRefs.length; i++) {
_setElementId(this._renderer.getNativeElementSync(view.elementRefs[i]), [viewId, i]);
}
}
示例10: getComponentId
export function getComponentId(componentStringId: string) {
var id = _componentUIDs.get(componentStringId);
if (isBlank(id)) {
id = _nextComponentUID++;
_componentUIDs.set(componentStringId, id);
}
return id;
}