Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<template> layering proposal #813

Closed
wants to merge 11 commits into from
40 changes: 21 additions & 19 deletions text/0813-template-layering.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ the `<template>` syntax extension defined in [RFC #779][rfc-779] using
standard JavaScript:

```js
import { template } from '@ember/template-compilation';
import Hello from 'my-app/components/hello';
import { template } from "@ember/template-compilation";
import Hello from "my-app/components/hello";

// <template><Hello></template> becomes...
chancancode marked this conversation as resolved.
Show resolved Hide resolved
export default template(`<Hello />`, () => ({ Hello }));
Expand All @@ -30,9 +30,10 @@ export const Foo = template(`<Hello />`, () => ({ Hello }));
// export class Bar {
// <template><Hello /></template>
// }
export
@template(`<Hello />`, () => ({ Hello })
class Bar {
export class Bar {
static {
chancancode marked this conversation as resolved.
Show resolved Hide resolved
template(`<Hello />`, () => ({ Hello }), this);
}
}
```

Expand Down Expand Up @@ -140,9 +141,9 @@ function that servers as a middle ground between the `<template>` language
extension and the low-level primitives.

- It is designed to have the same semantics as the `<template>` feature (such
as the strict-mode opt-in, returning a template-only component when invoked
as a standalone expression), providing the same high-level programming model
for authoring components in standard JavaScript environments.
as the strict-mode opt-in, returning a template-only component when not
attached to a class), providing the same high-level programming model for
authoring components in standard JavaScript environments.

- It requires manually supplying the lexical scope variable bindings.

Expand Down Expand Up @@ -232,21 +233,17 @@ de-sugaring into `template()` calls:
import { template } from '@ember/template-compilation';
import Foo form 'somewhere';

export default @template(`<Foo />`, () => ({ Foo })) class Bar {
}
```

**TBD**: or perhaps... (we should only pick one)

```js
import { template } from '@ember/template-compilation';
import Foo form 'somewhere';

export default class Bar {
static { template(this, `<Foo />`, () => ({ Foo })) }
static {
template(`<Foo />`, () => ({ Foo }), this);
}
}
```

**Note**: In static initializer block isn't required here (though it is a
standard JavaScript feature). The `template()` function can wrap around the
class, or be applied after the class has been declared.

In these small snippets, the scope bindings may look very verbose compared to
the size of the templates, but in real-world templates, the ratio will improve.

Expand Down Expand Up @@ -338,6 +335,11 @@ lines anyway with an inline closure that you invoke inside the template.

**TBD**

```js
export @template(`<Hello />`, () => ({ Hello }) class Bar {
}
```

## Unresolved questions

**TBD**
chancancode marked this conversation as resolved.
Show resolved Hide resolved