Beispiel #1
0
/**
 * Removes "duplicate" records. It assumes that record evaluation does not have side-effects.
 *
 * Records that are not last in bindings are removed and all the indices of the records that depend
 * on them are updated.
 *
 * Records that are last in bindings CANNOT be removed, and instead are replaced with very cheap
 * SELF records.
 *
 * @internal
 */
function coalesce(srcRecords) {
    var dstRecords = [];
    var excludedIdxs = [];
    var indexMap = new collection_1.Map();
    var skipDepth = 0;
    var skipSources = collection_1.ListWrapper.createFixedSize(srcRecords.length);
    for (var protoIndex = 0; protoIndex < srcRecords.length; protoIndex++) {
        var skipRecord = skipSources[protoIndex];
        if (lang_1.isPresent(skipRecord)) {
            skipDepth--;
            skipRecord.fixedArgs[0] = dstRecords.length;
        }
        var src = srcRecords[protoIndex];
        var dst = _cloneAndUpdateIndexes(src, dstRecords, indexMap);
        if (dst.isSkipRecord()) {
            dstRecords.push(dst);
            skipDepth++;
            skipSources[dst.fixedArgs[0]] = dst;
        }
        else {
            var record = _mayBeAddRecord(dst, dstRecords, excludedIdxs, skipDepth > 0);
            indexMap.set(src.selfIndex, record.selfIndex);
        }
    }
    return _optimizeSkips(dstRecords);
}
Beispiel #2
0
/**
 * - Conditional skip of 1 record followed by an unconditional skip of N are replaced by  a
 *   conditional skip of N with the negated condition,
 * - Skips of 0 records are removed
 */
function _optimizeSkips(srcRecords) {
    var dstRecords = [];
    var skipSources = collection_1.ListWrapper.createFixedSize(srcRecords.length);
    var indexMap = new collection_1.Map();
    for (var protoIndex = 0; protoIndex < srcRecords.length; protoIndex++) {
        var skipRecord = skipSources[protoIndex];
        if (lang_1.isPresent(skipRecord)) {
            skipRecord.fixedArgs[0] = dstRecords.length;
        }
        var src = srcRecords[protoIndex];
        if (src.isSkipRecord()) {
            if (src.isConditionalSkipRecord() && src.fixedArgs[0] === protoIndex + 2 &&
                protoIndex < srcRecords.length - 1 &&
                srcRecords[protoIndex + 1].mode === proto_record_1.RecordType.SkipRecords) {
                src.mode = src.mode === proto_record_1.RecordType.SkipRecordsIf ? proto_record_1.RecordType.SkipRecordsIfNot :
                    proto_record_1.RecordType.SkipRecordsIf;
                src.fixedArgs[0] = srcRecords[protoIndex + 1].fixedArgs[0];
                protoIndex++;
            }
            if (src.fixedArgs[0] > protoIndex + 1) {
                var dst = _cloneAndUpdateIndexes(src, dstRecords, indexMap);
                dstRecords.push(dst);
                skipSources[dst.fixedArgs[0]] = dst;
            }
        }
        else {
            var dst = _cloneAndUpdateIndexes(src, dstRecords, indexMap);
            dstRecords.push(dst);
            indexMap.set(src.selfIndex, dst.selfIndex);
        }
    }
    return dstRecords;
}
 /**
  * Returns the {@link ViewMetadata} for a component:
  * - Set the {@link ViewMetadata} to the overridden view when it exists or fallback to the default
  * `ViewResolver`,
  *   see `setView`.
  * - Override the directives, see `overrideViewDirective`.
  * - Override the @View definition, see `setInlineTemplate`.
  *
  * @param component
  * @returns {ViewDefinition}
  */
 resolve(component) {
     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);
         overrides.forEach((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 ViewMetadata({ template: view.template, templateUrl: view.templateUrl, directives: directives });
     }
     var inlineTemplate = this._inlineTemplates.get(component);
     if (isPresent(inlineTemplate)) {
         view = new ViewMetadata({ template: inlineTemplate, templateUrl: null, directives: view.directives });
     }
     this._viewCache.set(component, view);
     return view;
 }
 setter(name) {
     if (this._setters.has(name)) {
         return this._setters.get(name);
     }
     else {
         return this.reflectionCapabilities.setter(name);
     }
 }
Beispiel #5
0
 StringMapWrapper.forEach(appEl.proto.directiveVariableBindings, (directiveIndex, name) => {
     if (isBlank(directiveIndex)) {
         localsMap.set(name, appEl.nativeElement);
     }
     else {
         localsMap.set(name, appEl.getDirectiveAtIndex(directiveIndex));
     }
 });
Beispiel #6
0
 /** @internal */
 _registerView(value, view) {
     var views = this._valueViews.get(value);
     if (isBlank(views)) {
         views = [];
         this._valueViews.set(value, views);
     }
     views.push(view);
 }
 method(name) {
     if (this._methods.has(name)) {
         return this._methods.get(name);
     }
     else {
         return this.reflectionCapabilities.method(name);
     }
 }
 resolve(component) {
     var view = this._cache.get(component);
     if (isBlank(view)) {
         view = this._resolve(component);
         this._cache.set(component, view);
     }
     return view;
 }
Beispiel #9
0
 collection_1.StringMapWrapper.forEach(appEl.proto.directiveVariableBindings, function (directiveIndex, name) {
     if (lang_1.isBlank(directiveIndex)) {
         localsMap.set(name, appEl.nativeElement);
     }
     else {
         localsMap.set(name, appEl.getDirectiveAtIndex(directiveIndex));
     }
 });
 /**
  * Overrides a directive from the component {@link ViewMetadata}.
  *
  * @param {Type} component
  * @param {Type} from
  * @param {Type} to
  */
 overrideViewDirective(component, from, to) {
     this._checkOverrideable(component);
     var overrides = this._directiveOverrides.get(component);
     if (isBlank(overrides)) {
         overrides = new Map();
         this._directiveOverrides.set(component, overrides);
     }
     overrides.set(from, to);
 }
 DebugElementViewListener.prototype.viewCreated = function (view) {
     var viewId = _nextId++;
     _allViewsById.set(viewId, view);
     _allIdsByView.set(view, viewId);
     for (var i = 0; i < view.elementRefs.length; i++) {
         var el = view.elementRefs[i];
         _setElementId(this._renderer.getNativeElementSync(el), [viewId, i]);
     }
 };
Beispiel #12
0
 dispatchRenderEvent(boundElementIndex, eventName, event) {
     var allowDefaultBehavior = true;
     if (isPresent(this.eventDispatcher)) {
         var locals = new Map();
         locals.set('$event', event);
         allowDefaultBehavior =
             this.eventDispatcher.dispatchRenderEvent(boundElementIndex, eventName, locals);
     }
     return allowDefaultBehavior;
 }
 _getInstruction(urlPath, urlParams, params) {
     if (isBlank(this.handler.componentType)) {
         throw new BaseException(`Tried to get instruction before the type was loaded.`);
     }
     var hashKey = urlPath + '?' + urlParams.join('?');
     if (this._cache.has(hashKey)) {
         return this._cache.get(hashKey);
     }
     var instruction = new ComponentInstruction(urlPath, urlParams, this.handler.data, this.handler.componentType, this.terminal, this.specificity, params);
     this._cache.set(hashKey, instruction);
     return instruction;
 }
Beispiel #14
0
 /** @internal */
 _deregisterView(value, view) {
     // `_WHEN_DEFAULT` is used a marker for non-registered whens
     if (value === _WHEN_DEFAULT)
         return;
     var views = this._valueViews.get(value);
     if (views.length == 1) {
         this._valueViews.delete(value);
     }
     else {
         ListWrapper.remove(views, view);
     }
 }
Beispiel #15
0
 set ngSwitch(value) {
     // Empty the currently active ViewContainers
     this._emptyAllActiveViews();
     // Add the ViewContainers matching the value (with a fallback to default)
     this._useDefault = false;
     var views = this._valueViews.get(value);
     if (isBlank(views)) {
         this._useDefault = true;
         views = normalizeBlank(this._valueViews.get(_WHEN_DEFAULT));
     }
     this._activateViews(views);
     this._switchValue = value;
 }
Beispiel #16
0
 returnView(view) {
     var protoView = view.proto;
     var pooledViews = this._pooledViewsPerProtoView.get(protoView);
     if (isBlank(pooledViews)) {
         pooledViews = [];
         this._pooledViewsPerProtoView.set(protoView, pooledViews);
     }
     var haveRemainingCapacity = pooledViews.length < this._poolCapacityPerProtoView;
     if (haveRemainingCapacity) {
         pooledViews.push(view);
     }
     return haveRemainingCapacity;
 }
Beispiel #17
0
 collection_1.MapWrapper.forEach(host, function (value, key) {
     var matches = lang_1.RegExpWrapper.firstMatch(hostRegExp, key);
     if (lang_1.isBlank(matches)) {
         hostAttributes.set(key, value);
     }
     else if (lang_1.isPresent(matches[1])) {
         hostProperties.set(matches[1], value);
     }
     else if (lang_1.isPresent(matches[2])) {
         hostListeners.set(matches[2], value);
     }
     else if (lang_1.isPresent(matches[3])) {
         hostActions.set(matches[3], value);
     }
 });
 MapWrapper.forEach(host, (value, key) => {
     var matches = RegExpWrapper.firstMatch(RenderDirectiveMetadata._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);
     }
 });
Beispiel #19
0
 /**
  * Updates this router and all descendant routers according to the given instruction
  */
 commit(instruction, _skipLocationChange = false) {
     this.currentInstruction = instruction;
     var next = _resolveToTrue;
     if (isPresent(this._outlet) && isPresent(instruction.component)) {
         var componentInstruction = instruction.component;
         if (componentInstruction.reuse) {
             next = this._outlet.reuse(componentInstruction);
         }
         else {
             next =
                 this.deactivate(instruction).then((_) => this._outlet.activate(componentInstruction));
         }
         if (isPresent(instruction.child)) {
             next = next.then((_) => {
                 if (isPresent(this._childRouter)) {
                     return this._childRouter.commit(instruction.child);
                 }
             });
         }
     }
     var promises = [];
     this._auxRouters.forEach((router, name) => {
         if (isPresent(instruction.auxInstruction[name])) {
             promises.push(router.commit(instruction.auxInstruction[name]));
         }
     });
     return next.then((_) => PromiseWrapper.all(promises));
 }
Beispiel #20
0
 /** @internal */
 _updateView() {
     this._clearViews();
     var view = this._caseViews.get(this._switchValue);
     if (!isPresent(view))
         view = this._getCategoryView(this._switchValue);
     this._activateView(view);
 }
 hasRoute(name, parentComponent) {
     var rules = this._rules.get(parentComponent);
     if (isBlank(rules)) {
         return false;
     }
     return rules.hasRoute(name);
 }
Beispiel #22
0
 generateAuxiliary(name, params) {
     var rule = this.auxRulesByName.get(name);
     if (isBlank(rule)) {
         return null;
     }
     return rule.generate(params);
 }
 recognizeAuxiliary(urlParse) {
     var routeRecognizer = this.auxRoutes.get(urlParse.path);
     if (isPresent(routeRecognizer)) {
         return [routeRecognizer.recognize(urlParse)];
     }
     return [PromiseWrapper.resolve(null)];
 }
 generateAuxiliary(name, params) {
     var pathRecognizer = this.auxNames.get(name);
     if (isBlank(pathRecognizer)) {
         return null;
     }
     return pathRecognizer.generate(params);
 }
 _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);
         });
     });
 }
 _dispatchEvent(eventData) {
     var dispatcher = this._eventDispatchRegistry.get(eventData.viewRef);
     this._zone.run(() => {
         eventData.locals['$event'] = deserializeGenericEvent(eventData.locals['$event']);
         dispatcher.dispatchRenderEvent(eventData.elementIndex, eventData.eventName, eventData.locals);
     });
 }
 recognizeAuxiliary(urlParse) {
     var pathRecognizer = this.auxRoutes.get(urlParse.path);
     if (isBlank(pathRecognizer)) {
         return null;
     }
     return pathRecognizer.recognize(urlParse);
 }
Beispiel #28
0
 getView(protoView) {
     var pooledViews = this._pooledViewsPerProtoView.get(protoView);
     if (isPresent(pooledViews) && pooledViews.length > 0) {
         return pooledViews.pop();
     }
     return null;
 }
Beispiel #29
0
 init(rootNodesOrAppElements, allNodes, disposables, appElements) {
     this.rootNodesOrAppElements = rootNodesOrAppElements;
     this.allNodes = allNodes;
     this.disposables = disposables;
     this.appElements = appElements;
     var localsMap = new Map();
     StringMapWrapper.forEach(this.proto.templateVariableBindings, (templateName, _) => { localsMap.set(templateName, null); });
     for (var i = 0; i < appElements.length; i++) {
         var appEl = appElements[i];
         StringMapWrapper.forEach(appEl.proto.directiveVariableBindings, (directiveIndex, name) => {
             if (isBlank(directiveIndex)) {
                 localsMap.set(name, appEl.nativeElement);
             }
             else {
                 localsMap.set(name, appEl.getDirectiveAtIndex(directiveIndex));
             }
         });
     }
     var parentLocals = null;
     if (this.proto.type !== ViewType.COMPONENT) {
         parentLocals =
             isPresent(this.containerAppElement) ? this.containerAppElement.parentView.locals : null;
     }
     if (this.proto.type === ViewType.COMPONENT) {
         // Note: the render nodes have been attached to their host element
         // in the ViewFactory already.
         this.containerAppElement.attachComponentView(this);
         this.containerAppElement.parentView.changeDetector.addViewChild(this.changeDetector);
     }
     this.locals = new Locals(parentLocals, localsMap);
     this.changeDetector.hydrate(this.context, this.locals, this, this.pipes);
     this.viewManager.onViewCreated(this);
 }
 hasRoute(name, parentComponent) {
     var componentRecognizer = this._rules.get(parentComponent);
     if (isBlank(componentRecognizer)) {
         return false;
     }
     return componentRecognizer.hasRoute(name);
 }