本文整理汇总了TypeScript中@compo/exports.Compo.initialize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Compo.initialize方法的具体用法?TypeScript Compo.initialize怎么用?TypeScript Compo.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@compo/exports.Compo
的用法示例。
在下文中一共展示了Compo.initialize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: customTag_define
customTag_define(template).done(() => {
var Foo = Compo.initialize('Foo');
deepEq_(Foo.getJsExports_Prop(), { name: 'Foo'});
deepEq_(Foo.getJsExports_PropAlias(), { name: 'Foo'});
eq_(Foo.getTextImport(), 'Hello foo baz!');
eq_(Foo.getTextAlikeImport(), 'name=Baz');
done();
});
示例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 { Compo } from '@compo/exports';
UTest({
'should include template without defining a component' () {
var template = `
define TestInclude {
div > @foo;
}
include TestInclude {
@foo > span;
}
`;
var compo = Compo.initialize(template);
eq_(compo.components.length, 1);
eq_(compo.components[0].compoName, 'define');
compo
.$
.has_('div > span');
}
});
示例4: Foo
h5 > '~[.]'
}
Foo (me, me.name.toUpperCase())
`;
var dom = renderer_render(template, { me: { name: 'ifoo' }});
return UTest.domtest(dom, `
find (h5) > text rewritten;
`);
}
},
'should created binded function' () {
var template = `
let Foo {
function self test () {
this.testy = 'Lorem';
}
div;
}
Foo;
`;
var root = Compo.initialize(template);
var foo = root.find('Foo');
is_(foo.test, 'Function');
var fn = foo.test;
fn.call(null);
eq_(foo.testy, 'Lorem');
}
});
示例5: Compo
'Scoped Template' () {
var Foo = Compo({
template: '2_Y_Define; 2_Y_Let;'
});
customTag_define('RTFoo', Foo);
customTag_define('RTFoo', `
define 2_Y_Define {}
let 2_Y_Let {}
`);
'> get from global'
var x = customTag_get('2_Y_Define');
is_(x, 'Function');
eq_(x.name, 'CompoBase');
'> should be scoped'
var x = customTag_get('2_Y_Let');
eq_(x, null);
'> get from scope'
var x = customTag_get('2_Y_Let', Foo);
is_(x, 'Function');
eq_(x.name, 'CompoBase');
'> render with the children'
var foo = Compo.initialize(Foo);
is_(foo.find('2_Y_Let'), 'Object');
}
}
})
示例6: Foo
$(dom)
.filter('h4')
.eq_('length', 1)
.eq_('text', 'HELLO');
},
'... for arguments' () {
var template = `
define Foo (user) {
function testFn () {
return user.name;
}
}
`;
customTag_define(template);
var Wrapper = Compo.initialize('Foo (bob)', { bob: { name: 'IBob'}});
var Foo = Wrapper.find('Foo');
eq_(Foo.testFn(), 'IBob');
},
'// (should be implemented: binding and setter problem)... for variables' () {
var template = `
define Foo {
var WIDTH = 10 / 2;
function onRenderStart () {
this.width = WIDTH;
}
}
`;
var Foo = Compo.initialize('Foo');
示例7: customTag_define
{ 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: [
{ text: 'iBar' }
]
});
}
},
'should superpose trees': {
'should copy id attributes from one tree to another' () {
var treeA = parser_parse('div > span');
示例8: customTag_define
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.$, `
find(button) > click;
`)
.then(() => {
var foo = compo.find('Foo');
eq_(foo.scope.called, true);
eq_(parentFn.callCount, 0);
});
}
})
示例9: onRenderStart
'should call onRenderStart' () {
var template = `
define foo {
function onRenderStart(model) {
eq_(model.name, 'Foo');
this.parent.count = this.parent.count == null
? 1
: ++this.parent.count
;
}
}
foo;
foo;
`;
var app = Compo.initialize(template, { name: 'Foo' });
var Foo = customTag_get('foo');
is_(Foo.prototype.onRenderStart, 'Function');
eq_(app.components.length, 3);
eq_(app.count, 2);
},
'should define a function' () {
var template = `
define foo {
function fooBar() {
return 'hello';
}
h4 > 'Foo'
}
foo;