本文整理匯總了TypeScript中@compo/exports.Compo函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Compo函數的具體用法?TypeScript Compo怎麽用?TypeScript Compo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Compo函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: has_
has_(x, { foo: { name: 'Foo1' }});
done();
}, 300);
}
}));
renderer_render(`
import async * as X from '/test/tmpl/modules/data_foo_1.js';
TestAsync;
`);
},
'should await the component': {
'simple await' (done) {
customTag_define('TestAsync', Compo({
onRenderStart () {
var x = this.$scope('X');
has_(x, { foo: { name: 'Foo2' }});
done();
}
}));
renderer_render(`
import async * as X from '/test/tmpl/modules/data_foo_2.js';
await (X) > TestAsync;
`);
},
'progress await' (done) {
customTag_define('TestAsync', Compo({
onRenderStart () {
var x = this.$scope('X');
has_(x, { foo: { name: 'Foo3' }});
$(dom)
示例2: UTest
import { customTag_define } from '@core/custom/exports'
import { Compo } from '@compo/exports'
UTest({
'attributes': {
'components' : {
'should use parent as `this` in expressions' () {
customTag_define('Foo', Compo({
myNum: 5
}));
customTag_define('Bar', Compo({
myNum: 7
}));
var compo = Compo.initialize('Bar > Foo test=~[this.myNum] > div test="~[this.myNum]"');
var foo = compo.find('Foo');
is_(foo.attr.test, 'Number');
eq_(foo.attr.test, 7);
var divAttrVal = compo.$.filter('div').attr('test');
is_(divAttrVal, 'String');
eq_(divAttrVal, '5');
}
}
}
})
示例3: UTest
import { customTag_define } from '@core/custom/tag';
import { renderer_render } from '@core/renderer/exports';
import { Compo } from '@compo/exports';
declare var sinon;
UTest({
'should set elements property' () {
let div = renderer_render(`
div
[style.position] = relative
[style.borderTopWidth] = 2em
;
`);
eq_(div.style.position, 'relative');
eq_(div.style.borderTopWidth, '2em');
},
'should set components properties' () {
let fn = sinon.spy(function(model){
eq_(this.a.b.c, 'd');
});
customTag_define('Foo', Compo({
onRenderStart: fn
}))
renderer_render('Foo [a.b.c] = d');
eq_(fn.callCount, 1);
}
});
示例4: customTag_get
define FooFromTmpl {
h4 > 'FooFromTmpl'
}
`)
var compo = customTag_get('FooFromTmpl');
is_(compo, 'Function');
var dom = renderer_render('FooFromTmpl');
return UTest.domtest(dom, `
find('h4') > text FooFromTmpl;
`);
},
'let' () {
'> create owner component'
var Foo = Compo({});
customTag_define('Foo', Foo);
'> register from template in the owners scope'
customTag_registerFromTemplate(`
let LetBaz {
h4 > 'LetBaz'
}
`, Foo);
listeners_on('error', assert.await(error => has_(error.message, 'LetBaz')));
var dom = renderer_render(`
Foo {
LetBaz;
}
LetBaz;
示例5: UTest
import { customTag_define } from '@core/custom/tag';
import { Compo } from '@compo/exports';
import { jMask } from '@mask-j/jMask';
import { renderer_render } from '@core/renderer/exports';
import { parser_parse, mask_stringify } from '@core/parser/exports';
import { mask_config } from '@core/api/config';
UTest({
$before () {
customTag_define('JustAContainer', Compo({}));
},
'function source' () {
var template = `
function doSmth (foo, bar) {
return Service(foo);
};
`;
var node = jMask(template).filter('function').get(0);
deepEq_(node.args, [{prop:'foo'}, {prop:'bar'}]);
var clean = str => str.replace(/\s*/g, '');
eq_(clean(node.body), clean('return Service(foo);'))
},
'function node' () {
var dom = renderer_render(`
JustAContainer {
function doChange() {
this.$.text('B');
}
slot change () {
示例6: deepEq_
'should map tree': {
'should map nodes tree' () {
var ast = mask_TreeWalker.map(parser_parse('div > span'), node => {
return { tagName: node.tagName.toUpperCase() };
});
deepEq_(ast, {
tagName: 'DIV',
nodes: [
{ tagName: 'SPAN' }
]
});
},
'should map components tree' () {
customTag_define('Foo', Compo({
serialize () {
return 'iFoo'
},
}));
customTag_define('Bar', Compo({
serialize () {
return 'iBar'
}
}));
var root = Compo.initialize('Foo > Bar');
var foo = Compo.find(root, 'Foo');
var tree = mask_TreeWalker.map(foo, compo => {
return { text: compo.serialize() };
});
deepEq_(tree, {
text: 'iFoo',
components: [
示例7: UTest
import { customTag_define } from '@core/custom/exports'
import { Compo } from '@compo/exports'
import '@core/feature/methods/exports'
import '@core/feature/modules/exports'
declare var sinon;
UTest({
'slot should be private (do not pass the signal to parent)' () {
var parentFn = sinon.spy();
customTag_define('FooParent', Compo({
slots: {
test: parentFn
}
}));
customTag_define(`
define Foo {
var called = false;
slot private test () {
this.scope.called = true;
}
button x-click=test;
}
`);
var compo = Compo.initialize('FooParent > Foo');
return UTest
.domtest(compo.$, `