@@ -8,13 +8,14 @@ Add a static template function in your `x-element` definition in order to
8
8
leverage automagical DOM generation and data binding:
9
9
10
10
``` javascript
11
- static template (html , { map } ) {
11
+ static template (html ) {
12
12
return ({ options, selectedId }) => {
13
13
return html `
14
14
<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
+ ])}
18
19
</select >
19
20
` ;
20
21
};
@@ -48,10 +49,6 @@ The following template languages are supported:
48
49
* ` html `
49
50
* ` svg `
50
51
51
- The following value updaters are supported:
52
-
53
- * ` map ` (can be used with content bindings)
54
-
55
52
** A note on non-primitive data:**
56
53
57
54
Because DOM manipulation is * slow* — template engines do their best to avoid it
@@ -234,7 +231,7 @@ html`<div>${bar}</div>`;
234
231
235
232
#### Array content binding
236
233
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 .
238
235
239
236
``` js
240
237
const bar = [
@@ -251,14 +248,16 @@ html`<div>${bar}</div>`;
251
248
// <div><span>one</span><span>two</span></div>
252
249
```
253
250
254
- #### The ` map ` content binding
251
+ #### Map content binding
255
252
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.
262
261
263
262
``` js
264
263
// Note that you can shuffle the deck without destroying / creating DOM.
@@ -269,8 +268,8 @@ const deck = [
269
268
];
270
269
const items = deck;
271
270
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)] );
274
273
html ` <div >${ bar} </div >` ;
275
274
// <div><span>♥1</span>…<span>♣A</span></div>
276
275
```
0 commit comments