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;
 });
Ejemplo n.º 2
0
 setterFn = function(element, value) {
   if (_isValidAttributeValue(dashCasedAttributeName, value)) {
     DOM.setAttribute(element, dashCasedAttributeName, stringify(value));
   } else {
     if (isPresent(value)) {
       throw new BaseException("Invalid " + dashCasedAttributeName +
       " attribute, only string values are allowed, got '" + stringify(value) + "'");
     }
     DOM.removeAttribute(element, dashCasedAttributeName);
   }
 };
Ejemplo n.º 3
0
 private static _genMessage(typeOrFunc, params: any[][]) {
   var signature = [];
   for (var i = 0, ii = params.length; i < ii; i++) {
     var parameter = params[i];
     if (isBlank(parameter) || parameter.length == 0) {
       signature.push('?');
     } else {
       signature.push(parameter.map(stringify).join(' '));
     }
   }
   return "Cannot resolve all parameters for '" + stringify(typeOrFunc) + "'(" +
          signature.join(', ') + "). " +
          "Make sure that all the parameters are decorated with Inject or have valid type annotations and that '" +
          stringify(typeOrFunc) + "' is decorated with Injectable.";
 }
Ejemplo n.º 4
0
 it('should create a ChangeDetectorDefinition for the root render proto view', () => {
   var renderPv = createRenderProtoView();
   var defs =
       getChangeDetectorDefinitions(bindDirective(MainComponent).metadata, renderPv, []);
   expect(defs.length).toBe(1);
   expect(defs[0].id).toEqual(`${stringify(MainComponent)}_comp_0`);
 });
Ejemplo n.º 5
0
  factory(t: Type): Function {
    switch (t.length) {
      case 0:
        return function() { return new t(); };
      case 1:
        return function(a1) { return new t(a1); };
      case 2:
        return function(a1, a2) { return new t(a1, a2); };
      case 3:
        return function(a1, a2, a3) { return new t(a1, a2, a3); };
      case 4:
        return function(a1, a2, a3, a4) { return new t(a1, a2, a3, a4); };
      case 5:
        return function(a1, a2, a3, a4, a5) { return new t(a1, a2, a3, a4, a5); };
      case 6:
        return function(a1, a2, a3, a4, a5, a6) { return new t(a1, a2, a3, a4, a5, a6); };
      case 7:
        return function(a1, a2, a3, a4, a5, a6, a7) { return new t(a1, a2, a3, a4, a5, a6, a7); };
      case 8:
        return function(a1, a2, a3, a4, a5, a6, a7, a8) {
          return new t(a1, a2, a3, a4, a5, a6, a7, a8);
        };
      case 9:
        return function(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
          return new t(a1, a2, a3, a4, a5, a6, a7, a8, a9);
        };
      case 10:
        return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
          return new t(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
        };
    };

    throw new Error(
        `Cannot create a factory for '${stringify(t)}' because its constructor has more than 10 arguments`);
  }
Ejemplo n.º 6
0
 _buildRenderDirective(directiveBinding) {
   var ann = directiveBinding.annotation;
   var renderType;
   var compileChildren = true;
   if ((ann instanceof Component) || (ann instanceof DynamicComponent)) {
     renderType = renderApi.DirectiveMetadata.COMPONENT_TYPE;
   } else if (ann instanceof Viewport) {
     renderType = renderApi.DirectiveMetadata.VIEWPORT_TYPE;
   } else if (ann instanceof Decorator) {
     renderType = renderApi.DirectiveMetadata.DECORATOR_TYPE;
     compileChildren = ann.compileChildren;
   }
   var setters = [];
   var readAttributes = [];
   ListWrapper.forEach(directiveBinding.dependencies, (dep) => {
     if (isPresent(dep.propSetterName)) {
       ListWrapper.push(setters, dep.propSetterName);
     }
     if (isPresent(dep.attributeName)) {
       ListWrapper.push(readAttributes, dep.attributeName);
     }
   });
   return new renderApi.DirectiveMetadata({
     id: stringify(directiveBinding.key.token),
     type: renderType,
     selector: ann.selector,
     compileChildren: compileChildren,
     events: isPresent(ann.events) ? MapWrapper.createFromStringMap(ann.events) : null,
     bind: isPresent(ann.bind) ? MapWrapper.createFromStringMap(ann.bind) : null,
     setters: setters,
     readAttributes: readAttributes
   });
 }
Ejemplo n.º 7
0
  /**
   * 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`);
    }
  }
Ejemplo n.º 8
0
function _readMetadata(componentType: Type) {
  let metadata = reflector.annotations(componentType).filter(f => f instanceof RoutesMetadata);
  if (metadata.length === 0) {
    throw new BaseException(
        `Component '${stringify(componentType)}' does not have route configuration`);
  }
  return metadata[0];
}
Ejemplo n.º 9
0
 it('should not allow overriding a view after it has been resolved', () => {
   viewResolver.resolve(SomeComponent);
   expect(() => {
     viewResolver.setView(SomeComponent, new View({template: 'overridden template'}));
   })
       .toThrowError(
           `The component ${stringify(SomeComponent)} has already been compiled, its configuration can not be changed`);
 });
Ejemplo n.º 10
0
 it('should not allow overriding a directive after its view has been resolved', () => {
   viewResolver.resolve(SomeComponent);
   expect(() => {
     viewResolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective);
   })
       .toThrowError(
           `The component ${stringify(SomeComponent)} has already been compiled, its configuration can not be changed`);
 });