peerlibrary / meteor-blaze-components

Reusable components for Blaze
http://components.meteorapp.com/
BSD 3-Clause "New" or "Revised" License
354 stars 26 forks source link

Write template HTML within component JS? #141

Closed IamCarbonMan closed 8 years ago

IamCarbonMan commented 8 years ago

Right now I have something like the following:

template.html

<template name="foo">
  <!-- some HTML here -->
</template>

component.js

class FooComponent extends BlazeComponent {
  template () {
    return "foo";
  }
  // some JS here
}

I'd rather write it like this:

class FooComponent extends BlazeComponent {
  template () {
    <template name="foo">
      <!-- some HTML here -->
    </template
  }
  // some JS here
}

The ability to combine the HTML and JS of a single component in the same place like this is one of the major strengths of JSX and I'm sure would be appreciated by anybody Blaze Components. Perhaps add a Meteor build plugin that just splits the HTML out of BlazeComponents' template attribute and puts it into an HTML file, adding an import in the original JS file?

mitar commented 8 years ago

This is being discussed as part of Blaze itself: https://github.com/meteor/blaze/issues/94

The plan is to have:

<template name="foo">
  <!-- some HTML here -->
</template>

<script>
class FooComponent extends BlazeComponent {
  template () {
    return "foo";
  }
  // some JS here
}
</script>
mitar commented 8 years ago

So I will be closing this in favor of that.