当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript CustomElementResource.define方法代码示例

本文整理汇总了TypeScript中@aurelia/runtime.CustomElementResource.define方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CustomElementResource.define方法的具体用法?TypeScript CustomElementResource.define怎么用?TypeScript CustomElementResource.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@aurelia/runtime.CustomElementResource的用法示例。


在下文中一共展示了CustomElementResource.define方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('100', function () {
    const App = CE.define(
      {
        name: 'app',
        template: '${a}<foo b.two-way="a"></foo>',
        dependencies: [
          CE.define(
            {
              name: 'foo',
              template: '${b}',
              bindables: ['b']
            },
            class {
              public b: string;

              public attached(this: this & ICustomElement<Node>): void {
                expect(this.b).to.equal('x');
                expect(this.$host.textContent).to.equal('x');
                this.b = 'y';
              }
            }
          )
        ]
      },
      class {
        public a: string;

        public bound(this: this & ICustomElement<Node>): void {
          expect(this.a).to.equal('x');
        }

        public attached(this: this & ICustomElement<Node>): void {
          expect(this.a).to.equal('y');
          expect(this.$host.textContent).to.equal('xx');
        }
      }
    );

    const host = ctx.createElement('div');
    const component = new App();

    component.a = 'x';

    const au = new Aurelia(ctx.container);
    au.app({ host, component });
    au.start();

    expect(host.textContent).to.equal('xx');

    ctx.lifecycle.processFlushQueue(LF.none);

    expect(component.a).to.equal('y');
    expect(host.textContent).to.equal('yy');
  });
开发者ID:aurelia,项目名称:aurelia,代码行数:54,代码来源:binding-commands.spec.ts

示例2: it

      it(`bindSpec ${bindSpec.t}, templateSpec ${templateSpec.t}`, function () {
        const { forof, item, expected, initialize } = bindSpec;
        const { createTemplate } = templateSpec;

        const ctx = TestContext.createHTMLTestContext();
        const { container } = ctx;
        container.register(TestConfiguration);

        const markup = createTemplate(forof, item);
        const App = CustomElementResource.define({ name: 'app', template: markup }, class {});

        const host = ctx.createElement('div');
        const component = new App();
        initialize(component);

        const au = new Aurelia(container);
        au.app({ host, component });
        au.start();

        expect(host.textContent).to.equal(expected);

        au.stop();

        expect(host.textContent).to.equal('');
      });
开发者ID:aurelia,项目名称:aurelia,代码行数:25,代码来源:repeater.spec.ts

示例3: it

  it(`@containerless yields ContainerlessProjector (with child)`, function () {
    const parent = ctx.createElement('div');
    const host = ctx.createElement('div');
    const child = ctx.createElement('div');
    parent.appendChild(host);
    host.appendChild(child);
    const Foo = CustomElementResource.define(
      {
        name: 'foo',
        containerless: true
      },
      class {}
    ) as ICustomElementType<Node>;
    const component = new Foo();
    const projector = locator.getElementProjector(dom, component, host, Foo.description);

    expect(projector).to.be.instanceof(ContainerlessProjector);
    expect(projector['childNodes'][0]).to.equal(child);
    expect(host.parentNode).to.equal(null);
    expect(parent.firstChild).to.be.instanceof(ctx.Comment);
    expect(parent.firstChild.textContent).to.equal('au-start');
    expect(parent.lastChild).to.be.instanceof(ctx.Comment);
    expect(parent.lastChild.textContent).to.equal('au-end');
    expect(parent.firstChild.nextSibling['$customElement']).to.equal(component);
    expect(projector.provideEncapsulationSource()).not.to.equal(projector['host']);
    expect(projector.provideEncapsulationSource()).to.equal(parent);
  });
开发者ID:aurelia,项目名称:aurelia,代码行数:27,代码来源:projector-locator.spec.ts

示例4: req

      req(depsToLoad, function (): void {
        const templateImport = parseImport(name);
        const templateSource = {
          name: kebabCase(templateImport.basename),
          template: description.template,
          build: {
            required: true,
            compiler: 'default'
          },
          dependencies: Array.prototype.slice.call(arguments, 1)
        };

        onLoad({default: CustomElementResource.define(templateSource, null)});
      });
开发者ID:aurelia,项目名称:aurelia,代码行数:14,代码来源:component.ts

示例5: it

  it('05.', function () {
    let boundCalls = 0;

    @customElement({ name: 'foo1', template: `<template><foo2 value.bind="value" value2.bind="value1"></foo2>\${value}</template>` })
    class Foo1 {
      @bindable()
      public value: any;
      public value1: any;
      public bound(): void {
        expect(this.value).to.equal('w00t', 'Foo1.this.value');
        expect(this.value1).to.equal('w00t1', 'Foo1.this.value1');
        boundCalls++;
      }
      public valueChanged(newValue: any): void {
        this.value1 = `${newValue}1`;
      }
    }

    @customElement({ name: 'foo2', template: `<template><foo3 value.bind="value" value2.bind="value2"></foo3>\${value}</template>` })
    class Foo2 {
      @bindable()
      public value: any;
      public value1: any;
      @bindable()
      public value2: any;
      public bound(): void {
        expect(this.value).to.equal('w00t', 'Foo2.this.value');
        expect(this.value1).to.equal('w00t1', 'Foo2.this.value1');
        expect(this.value2).to.equal('w00t1', 'Foo2.this.value2');
        boundCalls++;
      }
      public valueChanged(newValue: any): void {
        this.value1 = `${newValue}1`;
      }
    }

    @customElement({ name: 'foo3', template: `<template><foo4 value.bind="value" value2.bind="value2"></foo4>\${value}</template>` })
    class Foo3 {
      @bindable()
      public value: any;
      public value1: any;
      @bindable()
      public value2: any;
      public bound(): void {
        expect(this.value).to.equal('w00t', 'Foo3.this.value');
        expect(this.value1).to.equal('w00t1', 'Foo3.this.value1');
        expect(this.value2).to.equal('w00t1', 'Foo3.this.value2');
        boundCalls++;
      }
      public valueChanged(newValue: any): void {
        this.value1 = `${newValue}1`;
      }
    }

    @customElement({ name: 'foo4', template: `<template><foo5 value.bind="value" value2.bind="value2"></foo5>\${value}</template>` })
    class Foo4 {
      @bindable()
      public value: any;
      public value1: any;
      @bindable()
      public value2: any;
      public bound(): void {
        expect(this.value).to.equal('w00t', 'Foo4.this.value');
        expect(this.value1).to.equal('w00t1', 'Foo4.this.value1');
        expect(this.value2).to.equal('w00t1', 'Foo4.this.value2');
        boundCalls++;
      }
      public valueChanged(newValue: any): void {
        this.value1 = `${newValue}1`;
      }
    }

    @customElement({ name: 'foo5', template: `<template>\${value}</template>` })
    class Foo5 {
      @bindable()
      public value: any;
      public value1: any;
      @bindable()
      public value2: any;
      public bound(): void {
        expect(this.value).to.equal('w00t', 'Foo5.this.value');
        expect(this.value1).to.equal('w00t1', 'Foo5.this.value1');
        expect(this.value2).to.equal('w00t1', 'Foo5.this.value2');
        boundCalls++;
      }
      public valueChanged(newValue: any): void {
        this.value1 = `${newValue}1`;
      }
    }

    const customElementCtors: any[] = [Foo1, Foo2, Foo3, Foo4, Foo5];
    const { container, lifecycle } = ctx;
    container.register(...customElementCtors);
    container.register(TestConfiguration);
    const host = ctx.createElement('app');
    const au = new Aurelia(container);
    const App = CustomElementResource.define({ name: 'app', template: '<template><foo1 value.bind="value"></foo1>\${value}</template>' }, null);
    const component = new App();
    component.value = 'w00t';
    au.app({ host, component }).start();
//.........这里部分代码省略.........
开发者ID:aurelia,项目名称:aurelia,代码行数:101,代码来源:custom-elements.spec.ts

示例6:

 () => CustomElementResource.define({ name: 'foo', bindables: { foo: {} } }, class Foo {})
开发者ID:aurelia,项目名称:aurelia,代码行数:1,代码来源:create-element.spec.ts


注:本文中的@aurelia/runtime.CustomElementResource.define方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。