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


TypeScript glimmer-object.computed函數代碼示例

本文整理匯總了TypeScript中glimmer-object.computed函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript computed函數的具體用法?TypeScript computed怎麽用?TypeScript computed使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: added

QUnit.test('list of properties updates when an additional property is added (such cache busting)', function() {
  let MyClass = EmberObject.extend({
    foo: computed(K),

    fooDidChange: observer('foo', function() {}),

    bar: computed(K)
  });

  let list = [];

  MyClass.eachComputedProperty(function(name) {
    list.push(name);
  });

  deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties');

  MyClass.reopen({
    baz: computed(K)
  });

  MyClass.create(); // force apply mixins

  list = [];

  MyClass.eachComputedProperty(function(name) {
    list.push(name);
  });

  deepEqual(list.sort(), ['bar', 'foo', 'baz'].sort(), 'expected three computed properties');
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:31,代碼來源:ember-computed-test.ts

示例2: computed

QUnit.test('reopening a parent with a computed property flushes the child', assert => {
  let MyClass = EmberObject.extend({
    hello: computed(function() {
      return "original hello";
    })
  });

  let SubClass = MyClass.extend({
    hello: computed(function() {
      return this._super();
    })
  });

  let GrandChild = SubClass.extend({
    hello: computed(function() {
      return this._super();
    })
  });

  MyClass.reopen({
    hello: computed(function() {
      return this._super() + " new hello";
    })
  });

  let sub: any = GrandChild.create();

  assert.equal(sub.hello, "original hello new hello");
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:29,代碼來源:ember-create-test.ts

示例3: testWithDefault

testWithDefault('complex dependent keys changing complex dependent keys', function(get, set) {
  let MyClass = EmberObject.extend({
    init() {
      this._super.apply(this, arguments);
      set(this, 'bar', { baz: 'BIFF' });
    },

    foo: computed(function() {
      return get(get(this, 'bar'), 'baz');
    }).property('bar.baz')
  });

  let Subclass = MyClass.extend({
    init() {
      this._super.apply(this, arguments);
      set(this, 'bar2', { baz: 'BIFF2' });
    },

    foo: computed(function() {
      return get(get(this, 'bar2'), 'baz');
    }).property('bar2.baz')
  });

  let obj2 = new Subclass();

  equal(get(obj2, 'foo'), 'BIFF2');

  set(get(obj2, 'bar'), 'baz', 'BLARG');
  equal(get(obj2, 'foo'), 'BIFF2', 'should not invalidate property');

  set(get(obj2, 'bar2'), 'baz', 'BLARG');
  equal(get(obj2, 'foo'), 'BLARG', 'should invalidate property');
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:33,代碼來源:ember-computed-test.ts

示例4: function

QUnit.test('overriding computed properties', function() {
  let MixinA, MixinB, MixinC, MixinD;
  let obj;

  MixinA = Mixin.create({
    aProp: computed(function() {
      return 'A';
    })
  });

  MixinB = Mixin.create({
    aProp: computed(function() {
      return this._super.apply(this, arguments) + 'B';
    })
  });

  MixinC = Mixin.create({
    aProp: computed(function() {
      return this._super.apply(this, arguments) + 'C';
    })
  });

  MixinD = Mixin.create({
    aProp: computed(function() {
      return this._super.apply(this, arguments) + 'D';
    })
  });

  obj = {};
  MixinA.apply(obj);
  MixinB.apply(obj);
  equal(get(obj, 'aProp'), 'AB', 'should expose super for B');

  obj = {};
  MixinA.apply(obj);
  MixinC.apply(obj);
  equal(get(obj, 'aProp'), 'AC', 'should expose super for C');

  obj = {};

  MixinA.apply(obj);
  MixinD.apply(obj);
  equal(get(obj, 'aProp'), 'AD', 'should define super for D');

  obj = { };
  mixin(obj, {
    aProp: computed(function(key) {
      return 'obj';
    })
  });

  MixinD.apply(obj);
  equal(get(obj, 'aProp'), 'objD', 'should preserve original computed property');
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:54,代碼來源:ember-metal-computed-test.ts

示例5: function

QUnit.test('can iterate over a list of computed properties for a class', function() {
  let MyClass = EmberObject.extend({
    foo: computed(function() {}),

    fooDidChange: observer('foo', function() {}),

    bar: computed(function() {}),

    qux: alias('foo')
  });

  let SubClass = MyClass.extend({
    baz: computed(function() {})
  });

  SubClass.reopen({
    bat: computed(function() {}).meta({ iAmBat: true })
  });

  let list = [];

  MyClass.eachComputedProperty(function(name) {
    list.push(name);
  });

  deepEqual(list.sort(), ['bar', 'foo', 'qux'], 'watched and unwatched computed properties are iterated');

  list = [];

  SubClass.eachComputedProperty(function(name, meta) {
    list.push(name);

    if (name === 'bat') {
      deepEqual(meta, { iAmBat: true });
    } else {
      deepEqual(meta, {});
    }
  });

  deepEqual(list.sort(), ['bar', 'bat', 'baz', 'foo', 'qux'], 'all inherited properties are included');
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:41,代碼來源:ember-computed-test.ts


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