Example #1
0
  toString():string {
    var items = [];
    var previous = [];
    var changes = [];
    var additions = [];
    var removals = [];
    var record:MapChangeRecord;

    for (record = this._mapHead; record !== null; record = record._next) {
      ListWrapper.push(items, stringify(record));
    }
    for (record = this._previousMapHead; record !== null; record = record._nextPrevious) {
      ListWrapper.push(previous, stringify(record));
    }
    for (record = this._changesHead; record !== null; record = record._nextChanged) {
      ListWrapper.push(changes, stringify(record));
    }
    for (record = this._additionsHead; record !== null; record = record._nextAdded) {
      ListWrapper.push(additions, stringify(record));
    }
    for (record = this._removalsHead; record !== null; record = record._nextRemoved) {
      ListWrapper.push(removals, stringify(record));
    }

    return "map: " + items.join(', ') + "\n" +
           "previous: " + previous.join(', ') + "\n" +
           "additions: " + additions.join(', ') + "\n" +
           "changes: " + changes.join(', ') + "\n" +
           "removals: " + removals.join(', ') + "\n";
  }
  onRecordChange(group, records:List) {
    var value = records[0].currentValue;
    var dest = records[0].protoRecord.dest;
    ListWrapper.push(this.log, dest + '=' + this._asString(value));

    var values = ListWrapper.map(records, (r) => r.currentValue);
    ListWrapper.push(this.loggedValues, values);
  }
Example #3
0
function constructResolvingPath(keys:List) {
  if (keys.length > 1) {
    var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
    var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
    return " (" + tokenStrs.join(' -> ') + ")";
  } else {
    return "";
  }
}
Example #4
0
 createSteps(component:AnnotatedType):List<CompileStep> {
   var annotation: Component = component.annotation;
   var directives = annotation.template.directives;
   var annotatedDirectives = ListWrapper.create();
   for (var i=0; i<directives.length; i++) {
     ListWrapper.push(annotatedDirectives, this._reader.annotatedType(directives[i]));
   }
   return createDefaultSteps(this._parser, annotatedDirectives);
 }
Example #5
0
 classList():List<string> {
   if (isBlank(this._classList)) {
     this._classList = ListWrapper.create();
     var elClassList = DOM.classList(this.element);
     for (var i = 0; i < elClassList.length; i++) {
       ListWrapper.push(this._classList, elClassList[i]);
     }
   }
   return this._classList;
 }
  componentDirectivesMetadata(annotation:Component, shadowDomStrategy:ShadowDomStrategy):List<Type> {
    var polyDirs = shadowDomStrategy.polyfillDirectives();
    var template = annotation.template;
    var templateDirs = isPresent(template) && isPresent(template.directives) ? template.directives : [];

    var res = [];
    res = ListWrapper.concat(res, templateDirs)
    res = ListWrapper.concat(res, polyDirs)

    return res;
  }
Example #7
0
function findFirstClosedCycle(keys:List) {
  var res = [];
  for(var i = 0; i < keys.length; ++i) {
    if (ListWrapper.contains(res, keys[i])) {
      ListWrapper.push(res, keys[i]);
      return res;
    } else {
      ListWrapper.push(res, keys[i]);
    }
  }
  return res;
}
Example #8
0
      it('should handle swapping element', () => {
        l = [1, 2];
        changes.check(l);

        ListWrapper.clear(l);
        ListWrapper.push(l, 2);
        ListWrapper.push(l, 1);
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['2[1->0]', '1[0->1]'],
          previous: ['1[0->1]', '2[1->0]'],
          moves: ['2[1->0]', '1[0->1]']
        }));
      });
Example #9
0
      it('should detect changes in list', () => {
        l = [];
        changes.check(l);

        ListWrapper.push(l, 'a');
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['a[null->0]'],
          additions: ['a[null->0]']
        }));

        ListWrapper.push(l, 'b');
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['a', 'b[null->1]'],
          previous: ['a'],
          additions: ['b[null->1]']
        }));

        ListWrapper.push(l, 'c');
        ListWrapper.push(l, 'd');
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['a', 'b', 'c[null->2]', 'd[null->3]'],
          previous: ['a', 'b'],
          additions: ['c[null->2]', 'd[null->3]']
        }));

        ListWrapper.removeAt(l, 2);
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['a', 'b', 'd[3->2]'],
          previous: ['a', 'b', 'c[2->null]', 'd[3->2]'],
          moves: ['d[3->2]'],
          removals: ['c[2->null]']
        }));

        ListWrapper.clear(l);
        ListWrapper.push(l, 'd');
        ListWrapper.push(l, 'c');
        ListWrapper.push(l, 'b');
        ListWrapper.push(l, 'a');
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['d[2->0]', 'c[null->1]', 'b[1->2]', 'a[0->3]'],
          previous: ['a[0->3]', 'b[1->2]', 'd[2->0]'],
          additions: ['c[null->1]'],
          moves: ['d[2->0]', 'b[1->2]', 'a[0->3]']
        }));
      });
Example #10
0
 parseFormatter() {
   var result = this.parseExpression();
   while (this.optionalOperator("|")) {
     if (this.parseAction) {
       this.error("Cannot have a formatter in an action expression");
     }
     var name = this.expectIdentifierOrKeyword();
     var args = ListWrapper.create();
     while (this.optionalCharacter($COLON)) {
       ListWrapper.push(args, this.parseExpression());
     }
     result = new Formatter(result, name, args);
   }
   return result;
 }
Example #11
0
 _collectDirectives(pipelineElement) {
   var directives;
   if (isPresent(pipelineElement.decoratorDirectives)) {
     directives = ListWrapper.clone(pipelineElement.decoratorDirectives);
   } else {
     directives = [];
   }
   if (isPresent(pipelineElement.templateDirective)) {
     ListWrapper.push(directives, pipelineElement.templateDirective);
   }
   if (isPresent(pipelineElement.componentDirective)) {
     ListWrapper.push(directives, pipelineElement.componentDirective);
   }
   return directives;
 }
Example #12
0
 parseLiteralMap() {
   var keys = [];
   var values = [];
   this.expectCharacter($LBRACE);
   if (!this.optionalCharacter($RBRACE)) {
     do {
       var key = this.expectIdentifierOrKeywordOrString();
       ListWrapper.push(keys, key);
       this.expectCharacter($COLON);
       ListWrapper.push(values, this.parseExpression());
     } while (this.optionalCharacter($COMMA));
     this.expectCharacter($RBRACE);
   }
   return new LiteralMap(keys, values);
 }
Example #13
0
      it('should not report unnecessary moves', () => {
        l = ['a', 'b', 'c'];
        changes.check(l);

        ListWrapper.clear(l);
        ListWrapper.push(l, 'b');
        ListWrapper.push(l, 'a');
        ListWrapper.push(l, 'c');
        changes.check(l);
        expect(changes.toString()).toEqual(arrayChangesAsString({
          collection: ['b[1->0]', 'a[0->1]', 'c'],
          previous: ['a[0->1]', 'b[1->0]', 'c'],
          moves: ['b[1->0]', 'a[0->1]']
        }));
      });
 _collectDirectiveBindings(pipelineElement) {
   var directiveTypes = [];
   if (isPresent(pipelineElement.componentDirective)) {
     ListWrapper.push(directiveTypes, pipelineElement.componentDirective.type);
   }
   if (isPresent(pipelineElement.templateDirective)) {
     ListWrapper.push(directiveTypes, pipelineElement.templateDirective.type);
   }
   if (isPresent(pipelineElement.decoratorDirectives)) {
     for (var i=0; i<pipelineElement.decoratorDirectives.length; i++) {
       ListWrapper.push(directiveTypes, pipelineElement.decoratorDirectives[i].type);
     }
   }
   return directiveTypes;
 }
Example #15
0
function _extractToken(typeOrFunc, annotations) {
  var type;
  var depProps = [];

  for (var i = 0; i < annotations.length; ++i) {
    var paramAnnotation = annotations[i];

    if (paramAnnotation instanceof Type) {
      type = paramAnnotation;

    } else if (paramAnnotation instanceof Inject) {
      return _createDependency(paramAnnotation.token, false, false, []);

    } else if (paramAnnotation instanceof InjectPromise) {
      return _createDependency(paramAnnotation.token, true, false, []);

    } else if (paramAnnotation instanceof InjectLazy) {
      return _createDependency(paramAnnotation.token, false, true, []);

    } else if (paramAnnotation instanceof DependencyAnnotation) {
      ListWrapper.push(depProps, paramAnnotation);
    }
  }

  if (isPresent(type)) {
    return _createDependency(type, false, false, depProps);
  } else {
    throw new NoAnnotationError(typeOrFunc);
  }
}
Example #16
0
 _bindDirectiveProperties(typesWithAnnotations, pipelineElement) {
   var protoView = pipelineElement.inheritedProtoView;
   var directiveIndex = 0;
   ListWrapper.forEach(typesWithAnnotations, (typeWithAnnotation) => {
     var annotation = typeWithAnnotation.annotation;
     if (isBlank(annotation.bind)) {
       return;
     }
     StringMapWrapper.forEach(annotation.bind, (dirProp, elProp) => {
       var expression = isPresent(pipelineElement.propertyBindings) ?
         MapWrapper.get(pipelineElement.propertyBindings, elProp) :
           null;
       if (isBlank(expression)) {
         throw new BaseException('No element binding found for property '+elProp
           +' which is required by directive '+stringify(typeWithAnnotation.type));
       }
       protoView.bindDirectiveProperty(
         directiveIndex++,
         this._parser.parseBinding(expression),
         dirProp,
         this._closureMap.setter(dirProp)
       );
     });
   });
 }
Example #17
0
 it('detaching should update rootElementInjectors and parent RR', () => {
   viewPort.insert(fancyView);
   viewPort.remove();
   ListWrapper.forEach(fancyView.rootElementInjectors, (inj) =>
       expect(inj.parent).toBe(null));
   expect(parentView.recordRange.findFirstEnabledRecord()).toBe(null);
 });
Example #18
0
 function ast(exp:string) {
   var parts = exp.split(".");
   var cm = new ClosureMap();
   return ListWrapper.reduce(parts, function (ast, fieldName) {
     return new AccessMember(ast, fieldName, cm.getter(fieldName), cm.setter(fieldName));
   }, new ImplicitReceiver());
 }
Example #19
0
 insert(view, atIndex=-1): View {
   if (atIndex == -1) atIndex = this._views.length;
   ListWrapper.insert(this._views, atIndex, view);
   ViewPort.moveViewNodesAfterSibling(this._siblingToInsertAfter(atIndex), view);
   this.parentView.recordRange.addRange(view.recordRange);
   this._linkElementInjectors(view);
   return view;
 }
Example #20
0
 function evalAsts(asts, passedInContext = null) {
   var c = isBlank(passedInContext) ? td() : passedInContext;
   var res = [];
   for (var i=0; i<asts.length; i++) {
     ListWrapper.push(res, asts[i].eval(c));
   }
   return res;
 }
Example #21
0
 addDirective(directive:DirectiveMetadata) {
   var annotation = directive.annotation;
   this._allDirectives = null;
   if (annotation instanceof Decorator) {
     if (isBlank(this.decoratorDirectives)) {
       this.decoratorDirectives = ListWrapper.create();
     }
     ListWrapper.push(this.decoratorDirectives, directive);
     if (!annotation.compileChildren) {
       this.compileChildren = false;
     }
   } else if (annotation instanceof Template) {
     this.templateDirective = directive;
   } else if (annotation instanceof Component) {
     this.componentDirective = directive;
   }
 }
Example #22
0
 parseCallArguments() {
   if (this.next.isCharacter($RPAREN)) return [];
   var positionals = [];
   do {
     ListWrapper.push(positionals, this.parseExpression());
   } while (this.optionalCharacter($COMMA))
   return positionals;
 }
Example #23
0
 remove(atIndex=-1): View {
   if (atIndex == -1) atIndex = this._views.length - 1;
   var removedView = this.get(atIndex);
   ListWrapper.removeAt(this._views, atIndex);
   ViewPort.removeViewNodesFromParent(this.templateElement.parentNode, removedView);
   removedView.recordRange.remove();
   this._unlinkElementInjectors(removedView);
   return removedView;
 }
Example #24
0
 parseExpressionList(terminator:int):List {
   var result = [];
   if (!this.next.isCharacter(terminator)) {
     do {
       ListWrapper.push(result, this.parseExpression());
     } while (this.optionalCharacter($COMMA));
   }
   return result;
 }
Example #25
0
 getAllDirectives(): List<DirectiveMetadata> {
   if (this._allDirectives === null) {
     // Collect all the directives
     // When present the component directive must be first
     var directives = ListWrapper.create();
     if (isPresent(this.componentDirective)) {
       ListWrapper.push(directives, this.componentDirective);
     }
     if (isPresent(this.templateDirective)) {
       ListWrapper.push(directives, this.templateDirective);
     }
     if (isPresent(this.decoratorDirectives)) {
       directives = ListWrapper.concat(directives, this.decoratorDirectives);
     }
     this._allDirectives = directives;
   }
   return this._allDirectives;
 }
Example #26
0
 _resolveDependencies(key:Key, binding:Binding, forceAsync:boolean):List {
   try {
     var getDependency = d => this._getByKey(d.key, forceAsync || d.asFuture, d.lazy);
     return ListWrapper.map(binding.dependencies, getDependency);
   } catch (e) {
     this._clear(key);
     if (e instanceof ProviderError) e.addKey(key);
     throw e;
   }
 }
Example #27
0
function lex(text:string):List {
  var scanner:Scanner = new Scanner(text);
  var tokens:List<Token> = [];
  var token:Token = scanner.scanToken();
  while (token != null) {
    ListWrapper.push(tokens, token);
    token = scanner.scanToken();
  }
  return tokens;
}
Example #28
0
 _resolveDependencies(key:Key, binding:Binding):List {
   try {
     var getDependency = d => this.injector._getByKey(d.key, true, d.lazy);
     return ListWrapper.map(binding.dependencies, getDependency);
   } catch (e) {
     this.injector._setInstance(key, null);
     if (e instanceof ProviderError) e.addKey(key);
     throw e;
   }
 }
Example #29
0
  _getBinding(key:Key) {
    var binding = this._bindings.length <= key.id ?
      null :
      ListWrapper.get(this._bindings, key.id);

    if (isBlank(binding) && this._defaultBindings) {
      return bind(key.token).toClass(key.token);
    } else {
      return binding;
    }
  }
Example #30
0
  eval(context) {
    var obj = this.obj.eval(context);
    var key = this.key.eval(context);

    if (obj instanceof Map) {
      return MapWrapper.get(obj, key);
    } else if (obj instanceof List) {
      return ListWrapper.get(obj, key);
    } else {
      return obj[key];
    }
  }