當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Mixin.create方法代碼示例

本文整理匯總了TypeScript中@glimmer/object.Mixin.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mixin.create方法的具體用法?TypeScript Mixin.create怎麽用?TypeScript Mixin.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@glimmer/object.Mixin的用法示例。


在下文中一共展示了Mixin.create方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: foo

QUnit.test('applying several mixins at once with sup already defined causes infinite loop', assert => {
  let cnt = 0;
  let MixinA = Mixin.create({
    foo() { cnt++; }
  });

  let MixinB = Mixin.create({
    foo() {
      this._super.apply(this, arguments);
      cnt++;
    }
  });

  let MixinC = Mixin.create({
    foo() {
      this._super.apply(this, arguments);
      cnt++;
    }
  });

  let obj = {};
  mixin(obj, MixinA); // sup already exists
  mixin(obj, MixinB, MixinC); // must be more than one mixin

  cnt = 0;
  obj['foo']();
  assert.equal(cnt, 3, 'should invoke all 3 methods');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:28,代碼來源:ember-mixin-method-test.ts

示例2: meth

QUnit.test('mergedProperties\' overwriting methods can call _super', assert => {
  assert.expect(4);

  let MixinA = Mixin.create({
    mergedProperties: ['foo'],
    foo: {
      meth(a: string) {
        assert.equal(a, 'WOOT', '_super successfully called MixinA\'s `foo.meth` method');
        return 'WAT';
      }
    }
  });

  let MixinB = Mixin.create({
    foo: {
      meth() {
        assert.ok(true, 'MixinB\'s `foo.meth` method called');
        return this._super.apply(this, arguments);
      }
    }
  });

  let MixinC = Mixin.create({
    foo: {
      meth(a: string) {
        assert.ok(true, 'MixinC\'s `foo.meth` method called');
        return this._super(a);
      }
    }
  });

  let obj = mixin({}, MixinA, MixinB, MixinC);
  assert.equal(obj.foo.meth('WOOT'), 'WAT');
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:34,代碼來源:ember-metal-merged-properties-test.ts

示例3: apply

QUnit.test('detect() finds nested mixins', assert => {
  let MixinA = Mixin.create({});
  let MixinB = Mixin.create(MixinA);
  let obj = {};

  assert.equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');

  MixinB.apply(obj);
  assert.equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:10,代碼來源:ember-mixin-detect-test.ts

示例4: mixin

QUnit.skip('adding a concatenable property that already has a defined value should result in a concatenated value', assert => {
  let mixinA = Mixin.create({
    foobar: 'foo'
  });

  let mixinB = Mixin.create({
    concatenatedProperties: ['foobar'],
    foobar: 'bar'
  });

  let obj = mixin({}, mixinA, mixinB);
  assert.equal(get(obj, 'foobar'), 'foobar');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:13,代碼來源:ember-metal-concatenated-properties-test.ts

示例5: mixin

QUnit.test('mergedProperties\' properties can get overwritten', assert => {
  let MixinA = Mixin.create({
    mergedProperties: ['foo'],
    foo: { a: 1 }
  });

  let MixinB = Mixin.create({
    foo: { a: 2 }
  });

  let obj = mixin({}, MixinA, MixinB);
  assert.deepEqual(get(obj, 'foo'), { a: 2 });
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:13,代碼來源:ember-metal-merged-properties-test.ts


注:本文中的@glimmer/object.Mixin.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。