constructor() { super(); this._templates = MapWrapper.create(); this._inlineTemplates = MapWrapper.create(); this._templateCache = MapWrapper.create(); this._directiveOverrides = MapWrapper.create(); }
/** @internal */ _clone() { var clone = new TestComponentBuilder_1(this._injector); clone._viewOverrides = MapWrapper.clone(this._viewOverrides); clone._directiveOverrides = MapWrapper.clone(this._directiveOverrides); clone._templateOverrides = MapWrapper.clone(this._templateOverrides); return clone; }
TestComponentBuilder.prototype._clone = function () { var clone = new TestComponentBuilder(this._injector); clone._viewOverrides = collection_1.MapWrapper.clone(this._viewOverrides); clone._directiveOverrides = collection_1.MapWrapper.clone(this._directiveOverrides); clone._templateOverrides = collection_1.MapWrapper.clone(this._templateOverrides); return clone; };
it('should detect () syntax', () => { var results = process(el('<div (click)="b()"></div>')); expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('b()'); // "(click[])" is not an expected syntax and is only used to validate the regexp results = process(el('<div (click[])="b()"></div>')); expect(MapWrapper.get(results[0].eventBindings, 'click[]').source).toEqual('b()'); });
_buildAttribute(dep): string { var attributes = this._proto.attributes; if (isPresent(attributes) && MapWrapper.contains(attributes, dep.attributeName)) { return MapWrapper.get(attributes, dep.attributeName); } else { return null; } }
_addTerminal(map, name, selectable) { var terminalList = MapWrapper.get(map, name); if (isBlank(terminalList)) { terminalList = ListWrapper.create(); MapWrapper.set(map, name, terminalList); } ListWrapper.push(terminalList, selectable); }
_addPartial(map, name) { var matcher = MapWrapper.get(map, name); if (isBlank(matcher)) { matcher = new SelectorMatcher(); MapWrapper.set(map, name, matcher); } return matcher; }
Locals.prototype.set = function (name, value) { if (collection_1.MapWrapper.contains(this.current, name)) { collection_1.MapWrapper.set(this.current, name, value); } else { throw new lang_1.BaseException('Setting of new keys post-construction is not supported.'); } };
Locals.prototype.get = function (name) { if (collection_1.MapWrapper.contains(this.current, name)) { return collection_1.MapWrapper.get(this.current, name); } if (lang_1.isPresent(this.parent)) { return this.parent.get(name); } throw new lang_1.BaseException("Cannot find '" + name + "'"); };
ElementInjector.prototype._buildAttribute = function (dep) { var attributes = this._proto.attributes; if (lang_1.isPresent(attributes) && collection_1.MapWrapper.contains(attributes, dep.attributeName)) { return collection_1.MapWrapper.get(attributes, dep.attributeName); } else { return null; } };
put(record:CollectionChangeRecord) { // todo(vicb) handle corner cases var key = getMapKey(record.item); var duplicates = MapWrapper.get(this.map, key); if (!isPresent(duplicates)) { duplicates = new _DuplicateItemRecordList(); MapWrapper.set(this.map, key, duplicates); } duplicates.add(record); }
/** * Removes an [CollectionChangeRecord] from the list of duplicates. * * The list of duplicates also is removed from the map if it gets empty. */ remove(record:CollectionChangeRecord):CollectionChangeRecord { var key = getMapKey(record.item); // todo(vicb) //assert(this.map.containsKey(key)); var recordList:_DuplicateItemRecordList = MapWrapper.get(this.map, key); // Remove the list of duplicates when it gets empty if (recordList.remove(record)) { MapWrapper.delete(this.map, key); } return record; }
Locals.prototype.set = function (name, value) { // TODO(rado): consider removing this check if we can guarantee this is not // exposed to the public API. // TODO: vsavkin maybe it should check only the local map if (collection_1.MapWrapper.contains(this.current, name)) { collection_1.MapWrapper.set(this.current, name, value); } else { throw new lang_1.BaseException("Setting of new keys post-construction is not supported. Key: " + name + "."); } };
/** * Overrides a directive from the component {@link View}. * * @param {Type} component * @param {Type} from * @param {Type} to */ overrideTemplateDirective(component: Type, from: Type, to: Type): void { this._checkOverrideable(component); var overrides = MapWrapper.get(this._directiveOverrides, component); if (isBlank(overrides)) { overrides = MapWrapper.create(); MapWrapper.set(this._directiveOverrides, component, overrides); } MapWrapper.set(overrides, from, to); }
it('should bind directive properties with pipes', () => { var results = process( el('<div some-decor-props></div>'), { 'elProp': parser.parseBinding('someExpr', '') } ); var directiveBinding = results[0].directives[0]; var pipedProp = MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp'); var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp'); expect(pipedProp.ast.name).toEqual('double'); expect(pipedProp.ast.exp).toEqual(simpleProp.ast); expect(simpleProp.source).toEqual('someExpr'); });
/** * Once a component has been compiled, the AppProtoView is stored in the compiler cache. * * Then it should not be possible to override the component configuration after the component * has been compiled. * * @param {Type} component */ _checkOverrideable(component: Type): void { var cached = MapWrapper.get(this._templateCache, component); if (isPresent(cached)) { throw new BaseException(`The component ${stringify(component)} has already been compiled, its configuration can not be changed`); } }
_forEach(obj, fn:Function) { if (obj instanceof Map) { MapWrapper.forEach(obj, fn); } else { StringMapWrapper.forEach(obj, fn); } }
it('should store working property setters', () => { var element = el('<input bind-value="1">'); var results = process(element); var setter = MapWrapper.get(results[0].propertySetters, 'value'); setter(element, 'abc'); expect(element.value).toEqual('abc'); });
RouteRegistry.prototype.config = function (parentComponent, config) { assertValidConfig(config); var recognizer = collection_1.MapWrapper.get(this._rules, parentComponent); if (lang_1.isBlank(recognizer)) { recognizer = new route_recognizer_1.RouteRecognizer(); collection_1.MapWrapper.set(this._rules, parentComponent, recognizer); } if (collection_1.StringMapWrapper.contains(config, 'redirectTo')) { recognizer.addRedirect(config['path'], config['redirectTo']); return; } config = collection_1.StringMapWrapper.merge(config, { 'component': normalizeComponentDeclaration(config['component']) }); var component = config['component']; this.configFromComponent(component); recognizer.addConfig(config['path'], config, config['as']); };
// return an HTML representation of an element start tag - without its content // this is used to give contextual information in case of errors function getElementDescription(domElement) { var buf = new lang_1.StringJoiner(); var atts = dom_adapter_1.DOM.attributeMap(domElement); buf.add("<"); buf.add(dom_adapter_1.DOM.tagName(domElement).toLowerCase()); // show id and class first to ease element identification addDescriptionAttribute(buf, "id", collection_1.MapWrapper.get(atts, "id")); addDescriptionAttribute(buf, "class", collection_1.MapWrapper.get(atts, "class")); collection_1.MapWrapper.forEach(atts, function (attValue, attName) { if (attName !== "id" && attName !== "class") { addDescriptionAttribute(buf, attName, attValue); } }); buf.add(">"); return buf.toString(); }
/** * Lists types for which reflection information was not requested since * {@link #trackUsage} was called. This list could later be audited as * potential dead code. */ listUnusedKeys() { if (this._usedKeys == null) { throw new BaseException('Usage tracking is disabled'); } var allTypes = MapWrapper.keys(this._injectableInfo); return allTypes.filter(key => !SetWrapper.has(this._usedKeys, key)); }
bindVariable(name, value) { // Store the variable map from value to variable, reflecting how it will be used later by // RenderView. When a local is set to the view, a lookup for the variable name will take place keyed // by the "value", or exported identifier. For example, ng-repeat sets a view local of "index". // When this occurs, a lookup keyed by "index" must occur to find if there is a var referencing // it. MapWrapper.set(this.variableBindings, value, name); }
it('should store working property setters', () => { var element = el('<input some-decor-props>'); var results = process(element); var directiveBinding = results[0].directives[0]; var setter = MapWrapper.get(directiveBinding.propertySetters, 'value'); setter(element, 'abc'); expect(element.value).toEqual('abc'); });
it('should bind directive events', () => { var results = process( el('<div some-decor-events></div>') ); var directiveBinding = results[0].directives[0]; expect(MapWrapper.get(directiveBinding.eventBindings, 'click').source) .toEqual('doIt()'); });
Reflector.prototype.listUnusedKeys = function () { var _this = this; if (this._usedKeys == null) { throw new exceptions_1.BaseException('Usage tracking is disabled'); } var allTypes = collection_1.MapWrapper.keys(this._injectableInfo); return allTypes.filter(function (key) { return !collection_1.SetWrapper.has(_this._usedKeys, key); }); };
SelectControlValueAccessor.prototype._getOptionId = function (value) { for (var _i = 0, _a = collection_1.MapWrapper.keys(this._optionMap); _i < _a.length; _i++) { var id = _a[_i]; if (lang_1.looseIdentical(this._optionMap.get(id), value)) return id; } return null; };
it('should bind directive properties from attribute values', () => { var results = process( el('<div some-decor-props el-prop="someValue"></div>') ); var directiveBinding = results[0].directives[0]; var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp'); expect(simpleProp.source).toEqual('someValue'); });
function _createVariableNames(parentVariableNames, renderProtoView) { var res = lang_1.isBlank(parentVariableNames) ? [] : collection_1.ListWrapper.clone(parentVariableNames); collection_1.MapWrapper.forEach(renderProtoView.variableBindings, function (mappedName, varName) { res.push(mappedName); }); collection_1.ListWrapper.forEach(renderProtoView.elementBinders, function (binder) { collection_1.MapWrapper.forEach(binder.variableBindings, function (mappedName, varName) { res.push(mappedName); }); }); return res; }
function createDirectiveVariableBindings(renderElementBinder, directiveBindings) { var directiveVariableBindings = new Map(); collection_1.MapWrapper.forEach(renderElementBinder.variableBindings, function (templateName, exportAs) { var dirIndex = _findDirectiveIndexByExportAs(renderElementBinder, directiveBindings, exportAs); directiveVariableBindings.set(templateName, dirIndex); }); return directiveVariableBindings; }
function createVariableLocations(elementBinders) { var variableLocations = new Map(); for (var i = 0; i < elementBinders.length; i++) { var binder = elementBinders[i]; collection_1.MapWrapper.forEach(binder.variableBindings, function (mappedName, varName) { variableLocations.set(mappedName, i); }); } return variableLocations; }