How to use the @aurelia/jit.ResourceModel function in @aurelia/jit

To help you get started, we’ve selected a few @aurelia/jit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / 5-jit-html / has-multi-bindings.unit.spec.ts View on Github external
it(markup, function () {
      const ctx = TestContext.createHTMLTestContext();
      const { dom, container } = ctx;

      container.register(CustomAttribute.define({ name: 'attr', bindables: ['a', 'b', 'c'] }, class {}));

      const resources = new ResourceModel(container);

      const attrParser = container.get(IAttributeParser);
      const exprParser = container.get(IExpressionParser);
      const transformer = container.get(IAttrSyntaxTransformer);
      const factory = container.get(ITemplateElementFactory);

      const sut = new TemplateBinder(dom, resources, attrParser, exprParser, transformer);

      const template = factory.createTemplate(markup) as HTMLTemplateElement;
      const manifestRoot = sut.bind(template);
      const div = manifestRoot.childNodes[0] as PlainElementSymbol;

      const { customAttributes } = div;
      assert.strictEqual(customAttributes.length, 1, 'customAttributes.length');

      const [{ bindings }] = customAttributes;
github aurelia / aurelia / packages / __tests__ / jit-html / kitchen-sink.spec.ts View on Github external
it.skip(escaped, function () {
      const ctx = TestContext.createHTMLTestContext();
      const parser = new ctx.DOMParser();
      const doc = parser.parseFromString(markup, 'application/xml');
      const fakeSurrogate = { firstChild: doc, attributes: [] };

      const binder = new TemplateBinder(
        ctx.dom,
        new ResourceModel(new RuntimeCompilationResources(ctx.container)),
        ctx.container.get(IAttributeParser),
        ctx.container.get(IExpressionParser),
        ctx.container.get(IAttrSyntaxTransformer)
      );

      const result = binder.bind(fakeSurrogate as any);
      assert.strictEqual(result.physicalNode, fakeSurrogate, `result.physicalNode`);
    });
  }
github aurelia / aurelia / packages / jit-html / src / template-compiler.ts View on Github external
public compile(dom: IDOM, definition: ITemplateDefinition, descriptions: IResourceDescriptions): TemplateDefinition {
    if (Profiler.enabled) { enter(); }
    const binder = new TemplateBinder(dom, new ResourceModel(descriptions), this.attrParser, this.exprParser);
    const template = definition.template = this.factory.createTemplate(definition.template) as HTMLTemplateElement;
    const surrogate = binder.bind(template);
    if (definition.instructions === undefined || definition.instructions === (PLATFORM.emptyArray as typeof definition.instructions & typeof PLATFORM.emptyArray)) {
      definition.instructions = [];
    }
    if (surrogate.hasSlots === true) {
      definition.hasSlots = true;
    }

    this.instructionRows = definition.instructions as HTMLInstructionRow[];
    this.parts = {};

    const attributes = surrogate.attributes;
    const len = attributes.length;
    if (len > 0) {
      let surrogates: ITargetedInstruction[];
github aurelia / aurelia / packages / jit-html / dist / index.es6.js View on Github external
compile(dom, definition, descriptions) {
        if (Profiler.enabled) {
            enter$2();
        }
        const binder = new TemplateBinder(dom, new ResourceModel(descriptions), this.attrParser, this.exprParser);
        const template = definition.template = this.factory.createTemplate(definition.template);
        const surrogate = binder.bind(template);
        if (definition.instructions === undefined || definition.instructions === PLATFORM.emptyArray) {
            definition.instructions = [];
        }
        if (surrogate.hasSlots === true) {
            definition.hasSlots = true;
        }
        this.instructionRows = definition.instructions;
        this.parts = {};
        const attributes = surrogate.attributes;
        const len = attributes.length;
        if (len > 0) {
            let surrogates;
            if (definition.surrogates === undefined || definition.surrogates === PLATFORM.emptyArray) {
                definition.surrogates = Array(len);
github aurelia / aurelia / packages / jit-html / src / template-compiler.ts View on Github external
public compile(dom: IDOM, definition: ITemplateDefinition, descriptions: IResourceDescriptions): TemplateDefinition {
    const binder = new TemplateBinder(
      dom,
      new ResourceModel(descriptions),
      this.attrParser,
      this.exprParser,
      this.attrSyntaxModifier
    );
    const template = definition.template = this.factory.createTemplate(definition.template) as HTMLTemplateElement;
    const surrogate = binder.bind(template);
    if (definition.instructions === undefined || definition.instructions === (PLATFORM.emptyArray as typeof definition.instructions & typeof PLATFORM.emptyArray)) {
      definition.instructions = [];
    }
    if (surrogate.hasSlots === true) {
      definition.hasSlots = true;
    }
    if (definition.scopeParts === void 0 || definition.scopeParts === PLATFORM.emptyArray) {
      definition.scopeParts = [];
    }