Templates 用于创建可重用组件的模式

Templates 用于创建可重用组件的模式,templates,meteor,meteor-blaze,Templates,Meteor,Meteor Blaze,我目前正在开发一个长期的web应用程序Meteor。随着时间的推移,开发人员会来来去去去。因此,为了确保整个应用程序保持相同的外观和感觉,我希望能够使用meteor的模板系统创建标准组件。因此,功能模板不应该包含任何html,这都应该包含在组件模板中 我尝试过meteor polymer,但它只是使我的应用程序崩溃,感觉我应该使用meteor模板系统,而不是添加另一个库。聚合物很大程度上依赖于Meteor也依赖的模板标签,所以我不太确定 基本上,我希望在模板中执行以下操作: <templa

我目前正在开发一个长期的web应用程序Meteor。随着时间的推移,开发人员会来来去去去。因此,为了确保整个应用程序保持相同的外观和感觉,我希望能够使用meteor的模板系统创建标准组件。因此,功能模板不应该包含任何html,这都应该包含在组件模板中

我尝试过meteor polymer,但它只是使我的应用程序崩溃,感觉我应该使用meteor模板系统,而不是添加另一个库。聚合物很大程度上依赖于Meteor也依赖的模板标签,所以我不太确定

基本上,我希望在模板中执行以下操作:

<template name="someRandomFeature">
    {{#_RadioGroup name="dataInput" context=. formData=formData}}
        {{#_setLabel}}Test set{{/_setLabel}}
        {{#_addRow}}
            {{assignValues value="random"}}
            {{#_setCaption}}Random{/_setCaption}}
        {{/_addRow}}
        {{#_addRow}}
            {{assignValues value="expression"}}
            {{#_setCaption}}Expression: {{_TextInput name="testSetExpression" inline=true}}{{/_setCaption}}
        {{/_addRow}}
    {{/_RadioGroup}}

    {{#_FormGroup}}
        {{#_Config}}
            {{assignValues numRows=2}}
        {{/_Config}}

        {{#_setRow 0}}
            {{#_SetLabel}}Number of tests{{/_SetLabel}}
            {{#_setStageContent}}
                {{> _DropDown name="numberOfTests" items=numberOfTestsList formData=formData}}
            {{/_setStageContent}}
        {{/_setRow}}

        {{#_setRow 1}}
            {{#_SetLabel}}To email address{{/_SetLabel}}
            {{#_setStageContent}}
                {{> _TextInput name='respondentSelection' formData=formData}}
                <span class="help-block text-left">Send all test mails to this email adress</span>
            {{/_setStageContent}}
        {{/_setRow}}
    {{/_FormGroup}}
</template>

{{{#_radiogroupname=“dataInput”context=.formData=formData}}
{{{{u setLabel}}测试集{{/{u setLabel}
{{{u addRow}
{{assignValues value=“random”}
{{{{u setCaption}}随机{/{u setCaption}}
{{/{u addRow}}
{{{u addRow}
{{assignValues value=“expression”}
{{{#_setCaption}表达式:{{{{{u TextInput name=“testSetExpression”inline=true}}{{/_setCaption}
{{/{u addRow}}
{{/{u射线群}
{{{#_FormGroup}
{{{{#_Config}}
{{assignValues numRows=2}}
{{/{u Config}}
{{{#_setrow0}
{{{#_SetLabel}}测试数{{/_SetLabel}
{{{#_setStageContent}
{{>\u下拉列表name=“numberOfTests”items=numberOfTestsList formData=formData}
{{/_setStageContent}
{{/_setRow}
{{{u setRow 1}}
{{{{#_SetLabel}}至电子邮件地址{{/{u SetLabel}
{{{#_setStageContent}
{{>\u TextInput name='respondentSelection'formData=formData}
将所有测试邮件发送到此电子邮件地址
{{/_setStageContent}
{{/_setRow}
{{/{u FormGroup}
组件示例:

<template name="_FormGroup">
{{#with numRows=0 context=. formdata=formdata stage='config'}}
    {{#with execBlock UI.contentBlock}}
        <div class="form-group">
            {{#each getRows}}
                {{#unless ../disableLabels}}
                    <label class="control-label">
                        {{#with _constructStageList 1='rows' 2=_id 3='label'}}
                            {{> UI.contentBlock stage=this stageContext=../../context}}
                        {{/with}}
                    </label>
                {{/unless}}

                <div class="row{{#unless ../disableLabels}} controls{{/unless}}">
                    <div class="{{#if ../fullWidth}}col-md-16{{else}}col-md-8{{/if}}">
                        {{#with _constructStageList 1='rows' 2=_id 3='content'}}
                            {{> UI.contentBlock stage=this stageContext=../../context}}
                        {{/with}}
                    </div>
                </div>
            {{/each}}
        </div>
    {{/with}}
{{/with}}
</template>

{{{#其中numRows=0 context=.formdata=formdata stage='config'}
{{#with execBlock UI.contentBlock}
{{{#每个getRows}
{{{#除非../disableLabels}
{{{带{u constructStageList 1='rows'2={u id 3='label'}}
{{>UI.contentBlock阶段=此阶段文本=../../context}
{{/与}}
{{/除非}
{{{带{u constructStageList 1='rows'2='u id 3='content'}}
{{>UI.contentBlock阶段=此阶段文本=../../context}
{{/与}}
{{/每个}}
{{/与}}
{{/与}}
这是可行的,但:

  • 组件本身过于复杂,大量的上下文切换使得理解组件成为一个活地狱
  • 该模式已被打破,并进行了多次更新

  • 那么有没有人尝试过这样做?和/或找到了一种适用于此的模式?

    有一个正在开发的项目正是为了做到这一点:,来自。不过现在是私人的。您可以从()了解它。如果您不想等待UI Harness的发布,您应该从演讲视频中了解如何构建自己的组件。

    这的确是一个非常好的问题!你考虑过使用react吗?github上的项目已经打开了,只是关闭了一个.com网站(),但是这个解决方案虽然看起来很有希望,但并不是我想要的。