Skip to content

Commit 769e656

Browse files
committed
For your consideration — no more updaters.
Just testing out a thought. I think we might consdier removign the notion of updaters altogether — we might even remove `map`!
1 parent 9c71f4b commit 769e656

File tree

4 files changed

+223
-348
lines changed

4 files changed

+223
-348
lines changed

doc/TEMPLATES.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ Add a static template function in your `x-element` definition in order to
88
leverage automagical DOM generation and data binding:
99

1010
```javascript
11-
static template(html, { map }) {
11+
static template(html) {
1212
return ({ options, selectedId }) => {
1313
return html`
1414
<select name="my-options">
15-
${map(options, option => option.id, option => html`
16-
<option value="${option.value}" ?selected="${option.id === selectedId}">
17-
`)}
15+
${options.map(option => [
16+
option.id,
17+
html`<option value="${option.value}" ?selected="${option.id === selectedId}">`,
18+
])}
1819
</select>
1920
`;
2021
};
@@ -48,10 +49,6 @@ The following template languages are supported:
4849
* `html`
4950
* `svg`
5051

51-
The following value updaters are supported:
52-
53-
* `map` (can be used with content bindings)
54-
5552
**A note on non-primitive data:**
5653

5754
Because DOM manipulation is *slow* — template engines do their best to avoid it
@@ -234,7 +231,7 @@ html`<div>${bar}</div>`;
234231

235232
#### Array content binding
236233

237-
When the content being bound is an array of template results, you get a mapping.
234+
When the content being bound is an array of template results, you get a list.
238235

239236
```js
240237
const bar = [
@@ -251,14 +248,16 @@ html`<div>${bar}</div>`;
251248
// <div><span>one</span><span>two</span></div>
252249
```
253250

254-
#### The `map` content binding
251+
#### Map content binding
255252

256-
The `map` content binding adds some special behavior on top of the basic array
257-
content binding. In particular, it _keeps track_ of each child node based on
258-
an `identify` function declared by the caller. This enables the template engine
259-
to _move_ child nodes under certain circumstances (versus having to constantly
260-
destroy and recreate). And that shuffling behavior enables authors to animate
261-
DOM nodes across such transitions.
253+
When the content being bound is an array of key-value map entries (where the
254+
`key` is a unique string within the list and the `value` is a template result),
255+
you get also list. But, this value will come with some special behavior on top
256+
of the basic array content binding. In particular, it _keeps track_ of each
257+
child node based on the given `key` you declare. This enables the template
258+
engine to _move_ child nodes under certain circumstances (versus having to
259+
constantly destroy and recreate). And that shuffling behavior enables authors to
260+
animate DOM nodes across such transitions.
262261

263262
```js
264263
// Note that you can shuffle the deck without destroying / creating DOM.
@@ -269,8 +268,8 @@ const deck = [
269268
];
270269
const items = deck;
271270
const identify = item => item.id;
272-
const callback = item => html`<span>${item.text}</span>`;
273-
const bar = map(items, identify, callback);
271+
const template = item => html`<span>${item.text}</span>`;
272+
const bar = items.map(item => [identify(item), template(item)]);
274273
html`<div>${bar}</div>`;
275274
// <div><span>♥1</span>…<span>♣A</span></div>
276275
```

test/test-initialization-errors.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ it('errors are thrown in connectedCallback when template result fails to render'
8989
class TestElement extends XElement {
9090
static get properties() {
9191
return {
92-
strings: { default: () => [] },
92+
strings: { default: () => ['one', 'two', 'three'] },
9393
};
9494
}
95-
static template(html, { map }) {
95+
static template(html) {
9696
return ({ strings }) => {
97-
// In this case, "map" will fail when bound to an attribute.
98-
return html`<div foo="${map(strings, () => {}, string => html`${string}`)}"></div>`;
97+
// In this case, the array will fail if items are not template results.
98+
return html`<div>${strings}</div>`;
9999
};
100100
}
101101
}
@@ -120,13 +120,13 @@ it('errors are thrown in connectedCallback when template result fails to render
120120
class TestElement extends XElement {
121121
static get properties() {
122122
return {
123-
strings: { default: () => [] },
123+
strings: { default: () => ['one', 'two', 'three'] },
124124
};
125125
}
126-
static template(html, { map }) {
126+
static template(html) {
127127
return ({ strings }) => {
128-
// In this case, "map" will fail when bound to an attribute.
129-
return html`<div foo="${map(strings, () => {}, string => html`${string}`)}"></div>`;
128+
// In this case, the array will fail if items are not template results.
129+
return html`<div>${strings}</div>`;
130130
};
131131
}
132132
}

0 commit comments

Comments
 (0)