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