本文整理匯總了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');
});