Closed crapthings closed 8 years ago
<template name="hello">
<h3>hello</h3>
<script>
this.onRendered(function () {
console.log(1)
})
</script>
</template>
<template name="hello">
<h3>hello</h3>
<script>
Template.hello.onRendered(function () {
console.log(1)
})
</script>
</template>
Viewmodel sits on top of Blaze so you can use anything you would with Blaze. But the code you have there isn't valid Blaze. On Mar 28, 2016 5:21 AM, "crapthings" notifications@github.com wrote:
```hello
```— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ManuelDeLeon/viewmodel/issues/213#issuecomment-202344940
i know that is just some idea we can put blaze code and js code in same file like riot does
is it possible ?
new extension or spilt script from script tag
or let script acquire template context
https://github.com/numtel/meteor-template-from-string/issues/4
can viewmodel check if template is exist ?
if not then using a template from viewmodel self from meteor-template-from-string
turn this
Template.world = Template.fromString(`
<button>{{label}}</button>
{{> wiki}}
`)
Template.wiki = Template.fromString(`
<h1>hello</h1>
`)
Template.world.viewmodel({
label (label) {
return label || 'wtf'
},
click () {
alert(1)
}
})
like
Template.world.viewmodel({
template () { return `
<h1>${this.label()}</h1>
`}
label (label) {
return label || 'wtf'
},
click () {
alert(1)
}
})
so we can write 'blaze component' in same file
Search for dynamic templates. On Mar 29, 2016 2:41 AM, "crapthings" notifications@github.com wrote:
numtel/meteor-template-from-string#4 https://github.com/numtel/meteor-template-from-string/issues/4
can viewmodel check if template is exist ?
if not then using a template from viewmodel self from meteor-template-from-string
turn this
Template.world = Template.fromString(`
{{> wiki}}
`)
Template.wiki = Template.fromString(`
hello
`)
Template.world.viewmodel({
label (label) { return label || 'wtf' }, click () { alert(1) }
})
like
Template.world.viewmodel({ template () { return `
${this.label()}
`} label (label) { return label || 'wtf' },
click () { alert(1) }
})
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/ManuelDeLeon/viewmodel/issues/213#issuecomment-202779728
i mean use one file to write simple small component not split file into .html and .js
only js like what react and riot.
we use to
Template.templateName.events
Template.templateName.onCreated
Template.templateName.onRendered
blah blah blah
now we have
Template.templateName.viewmodel
events
onCreated
onRendered
sometimes we only write a small chunk html but we have to split to two files
templateName.html templateName.js
why not put into viewmodel only one file ? templateName.js
viewmodel can create Template itsself
btn.js
Template.btn.viewmodel({
template: Template.fromString(`
<button>{{label}}</button>
`),
events: {
click: function () {
alert(1)
}
},
label: function (label) {
return label || 'button'
}
})
vs
btn.html
<template name='btn'>
<button>{{label}}</button>
</template>
btn.js
Template.btn.events({
click: function () {
alert(1)
}
})
Template.btn.helpers({
label: function(label) {
return label || 'button'
}
})
Haven't tried but should be possible. Since templates are converted to .js anyway. Just need to know the Blaze API. Like React you could write in JSX or plain JS code.
See https://github.com/ccorcos/meteor-compile-view On Mar 29, 2016 7:18 PM, "crapthings" notifications@github.com wrote:
i mean use one file to write simple small component not split file into .html and .js
only js like what react and riot.
we use to
Template.templateName.events
Template.templateName.onCreated
Template.templateName.onRendered
blah blah blah
now we have
Template.templateName.viewmodel events onCreated onRendered
sometimes we only write a small chunk html but we have to split to two files
templateName.html templateName.js
why not put into viewmodel
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/ManuelDeLeon/viewmodel/issues/213#issuecomment-203181232
that looks cool
like react, or riot ?