• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript glimmer-object.computed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript glimmer-object.create函数代码示例发布时间:2022-05-25
下一篇:
TypeScript glimmer-object.alias函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap