本文整理汇总了TypeScript中glimmer-object.Mixin类的典型用法代码示例。如果您正苦于以下问题:TypeScript Mixin类的具体用法?TypeScript Mixin怎么用?TypeScript Mixin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mixin类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
QUnit.test('adding a prop that is not an array should make array', function() {
let MixinA = Mixin.create({
concatenatedProperties: ['foo'],
foo: 'bar'
});
let obj = mixin({}, MixinA);
deepEqual(get(obj, 'foo'), ['bar']);
});
示例2: function
QUnit.test('detect() finds a directly applied mixin', function() {
let MixinA = Mixin.create();
let obj = {};
equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinA.apply(obj);
equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
示例3: reopen
QUnit.test('using reopen() to add more properties to a simple', function() {
let MixinA = Mixin.create({ foo: 'FOO', baz: 'BAZ' });
MixinA.reopen({ bar: 'BAR', foo: 'FOO2' });
let obj = {};
MixinA.apply(obj);
equal(get(obj, 'foo'), 'FOO2', 'mixin() should override');
equal(get(obj, 'baz'), 'BAZ', 'preserve MixinA props');
equal(get(obj, 'bar'), 'BAR', 'include MixinB props');
});
示例4: adder
QUnit.skip('throws if you try to \'mixin\' a definition', assert => {
let myMixin = Mixin.create({
adder(arg1, arg2) {
return arg1 + arg2;
}
});
assert.throws(function() {
EmberObject.create(myMixin);
}, 'Ember.Object.create no longer supports mixing in other definitions, use .extend & .create seperately instead.');
});
示例5: function
QUnit.test('mergedProperties should be concatenated', function() {
let MixinA = Mixin.create({
mergedProperties: ['foo'],
foo: { a: true, b: true, c: true }
});
let MixinB = Mixin.create({
mergedProperties: 'bar',
foo: { d: true, e: true, f: true },
bar: { a: true, l: true }
});
let MixinC = Mixin.create({
bar: { e: true, x: true }
});
let obj = mixin({}, MixinA, MixinB, MixinC);
deepEqual(get(obj, 'mergedProperties'), ['foo', 'bar'], 'get mergedProperties');
deepEqual(get(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }, 'get foo');
deepEqual(get(obj, 'bar'), { a: true, l: true, e: true, x: true }, 'get bar');
});
示例6: function
QUnit.test('overriding toString', function() {
let MixinA = Mixin.create({
toString() { return 'FOO'; }
});
let obj = {};
MixinA.apply(obj);
equal(obj.toString(), 'FOO', 'should override toString w/o error');
obj = {};
mixin(obj, { toString() { return 'FOO'; } });
equal(obj.toString(), 'FOO', 'should override toString w/o error');
});