<!-- What is required in the template should also be included in the require attribute of the script element. -->
<script
require="jQuery, lib/makecomponent, lib/combineclassnames, ../childcomponent"
params="$, MakeComponent, CombineClassNames, ChildComponent">
var componentDecorator = MakeComponent(function (component) {
// Do something...
});
</script>
<template param="{
paragraphClass,
people,
match,
currentValue,
id
}" decorator="componentDecorator" export="path/to/MyComponent">
<div class="thing thing--light" data-enterprise-component="thing" data-model-id="@id">
<p class="@CombineClassNames("thing__paragraph", paragraphClass)">
Hello, world
<span class="thing__span" role="presentation">Some text</span>
</p>
<a href="#" class="btn btn--primary" data-component="thing-linkBtn">Click me</a>
@people.filter(function (person) {
return new RegExp(match).test(person.name);
}).map(function (person) {
return <@ChildComponent $arguments="[{ person: person, children: [ <p>Hello,</p> ] }]" />;
});
<input $value="@currentValue" class="input input--bordered ui--radius" data-component="thing-textBox"></input>
</div>
</template>
would be transpiled to (assuming AMD):
define("path/to/MyComponent",
["jQuery", "lib/makecomponent", "lib/combineclassnames", "../childcomponent"],
function ($, MakeComponent, CombineClassNames, ChildComponent) {
// generated from <script>
var componentDecorator = MakeComponent(function (component) {
// Do something...
});
// generated from <template>
return componentDecorator(function (_tempArg) {
var paragraphClass = _tempArg.paragraphClass,
people = _tempArg.people,
match = -tempArg.match,
currentValue = _tempArg.currentValue,
id = _tempArg.id;
return {
// generate the return value from the template...
};
});
});
Another template syntax:
would be transpiled to (assuming AMD):
Template syntax:
Prev update:
Alt:
Original version: