Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit c126ab8

Browse files
committed
Merge pull request #130 from Polymer/master
8/1 master -> stable
2 parents 5e76195 + 9faeb2c commit c126ab8

File tree

5 files changed

+36
-88
lines changed

5 files changed

+36
-88
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ MDV is designed to as two primitives which could eventually become standardized
136136

137137
MDV is mainly concerned with being robust and efficient in interacting with application data and keeping the DOM in sync , but more advanced behaviors can be accomplished via one or both of the following:
138138

139-
* [A Custom Syntax API](https://github.com/Polymer/mdv/blob/master/docs/syntax_api.md)
139+
* [A Binding Delegate API](https://github.com/Polymer/mdv/blob/master/docs/syntax_api.md)
140140
* [Expression Syntax](https://github.com/Polymer/mdv/blob/master/docs/expression_syntax.md)
141141

142142
### Advanced Topics

benchmark/index.html

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ <h3 style="margin-left: 440px">Binding Density</h3>
115115

116116
function changeBenchmark() {
117117
benchmark = window[benchmarkSelect.value];
118-
configSelect.innerHTML = '';
118+
configSelect.textContent = '';
119119
benchmark.configs.forEach(function(config) {
120120
var option = document.createElement('option');
121-
option.innerHTML = config;
121+
option.textContent = config;
122122
configSelect.appendChild(option);
123123
});
124124
}
@@ -133,8 +133,8 @@ <h3 style="margin-left: 440px">Binding Density</h3>
133133

134134
goButton.addEventListener('click', function() {
135135
goButton.disabled = true;
136-
goButton.innerHTML = 'Running...';
137-
ul.innerHTML = '';
136+
goButton.textContent = 'Running...';
137+
ul.textContent = '';
138138

139139
var bindingDensities = bindingDensityInput.value.split(',').map(function(val) {
140140
return Number(val) / 100;
@@ -148,8 +148,8 @@ <h3 style="margin-left: 440px">Binding Density</h3>
148148

149149
testTypes.forEach(function(testType, i) {
150150
var li = document.createElement('li');
151-
li.innerHTML = testType;
152-
li.setAttribute('style', 'color: ' + colors[i]);
151+
li.textContent = testType;
152+
li.style.color = colors[i];
153153
ul.appendChild(li);
154154
});
155155

@@ -159,12 +159,12 @@ <h3 style="margin-left: 440px">Binding Density</h3>
159159

160160
datasets = [];
161161

162-
timesCanvas.setAttribute('height', '400');
163-
timesCanvas.setAttribute('width', '800');
162+
timesCanvas.height = 400;
163+
timesCanvas.width = 800;
164164
timesCanvas.setAttribute('style', '');
165165

166166
var labels = bindingDensities.map(function(density) {
167-
return (density * 100) + '%';
167+
return density * 100 + '%';
168168
});
169169

170170
var timesArray = [];
@@ -176,32 +176,32 @@ <h3 style="margin-left: 440px">Binding Density</h3>
176176

177177
var ctx = timesCanvas.getContext("2d");
178178
new Chart(ctx).Line({
179-
labels : labels,
180-
datasets : timesArray.map(function(times, i) {
179+
labels: labels,
180+
datasets: timesArray.map(function(times, i) {
181181
return {
182-
fillColor : 'rgba(255, 255, 255, 0)',
183-
strokeColor : colors[i],
184-
pointColor : colors[i],
185-
pointStrokeColor : "#fff",
186-
data : times
182+
fillColor: 'rgba(255, 255, 255, 0)',
183+
strokeColor: colors[i],
184+
pointColor: colors[i],
185+
pointStrokeColor: "#fff",
186+
data: times
187187
};
188188
})
189189
}, {
190-
bezierCurve : false
190+
bezierCurve: false
191191
});
192192

193193
goButton.disabled = false;
194-
goButton.innerHTML = 'Run Benchmarks';
194+
goButton.textContent = 'Run Benchmarks';
195195
updateStatus();
196196
}
197197

198198
function updateStatus(density, testType, runCount) {
199199
if (!testType) {
200-
statusSpan.innerHTML = '';
200+
statusSpan.textContent = '';
201201
return;
202202
}
203203

204-
statusSpan.innerHTML = testType + ' ' + (100 * density) +
204+
statusSpan.textContent = testType + ' ' + (100 * density) +
205205
'% binding density, ' + runCount + ' runs';
206206
}
207207

docs/syntax_api.md

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ MDV's native features enables a wide-range of use cases, but (by design) don't a
2020

2121
* ... And anything else you'd like.
2222

23-
Enabling these features in MDV is a matter of implementing and registering a Custom Syntax.
23+
Enabling these features in MDV is a matter of implementing and registering a binding delegate.
2424

2525
### Basic usage
2626

27-
```html
28-
<template bind syntax="MySyntax">
29-
{{ What!Ever('crazy')->thing^^^I+Want(data) }}
30-
</template>
31-
```
32-
3327
```JavaScript
34-
HTMLTemplateElement.syntax['MySyntax'] = {
28+
templateElement.bindingDelegate = {
3529
getBinding: function(model, path, name, node) {
3630
// If this function is defined, the syntax can override
3731
// the default binding behavior
@@ -44,52 +38,9 @@ HTMLTemplateElement.syntax['MySyntax'] = {
4438
}
4539
```
4640

47-
### Custom Syntax Registration
48-
49-
A Custom Syntax is an object which contains one or more syntax methods which implement specialized behavior. This object is registered with MDV via the HTMLTemplateElement. The syntax need only implement syntax methods it requires to accomplish its goals.
50-
51-
```JavaScript
52-
var syntax = {
53-
getBinding: function(model, path, name, node) {},
54-
getInstanceModel: function(template, model) {}
55-
};
56-
HTMLTemplateElement.syntax['name'] = syntax;
57-
```
58-
59-
### Custom Syntax Usage
60-
61-
The `<template>` element can declare its intent to use a Custom Syntax by naming it in its `syntax` attribute:
62-
63-
```html
64-
<template syntax="MyCustomSyntaxName">
65-
...
66-
</template>
67-
```
68-
69-
If a `syntax` can be located via the registry by the `<template>`, the syntax's methods will be called to possibly override its default behavior.
70-
71-
When a `<template>` inserts an new instance fragment into the DOM,
72-
73-
* If a syntax used and located
74-
* ...and it contains sub-templates
75-
* ...and the sub-template does not have a syntax attribute
76-
77-
... Then the sub-template will "inherit" the parent's syntax. e.g.:
78-
79-
```html
80-
<template bind syntax="FooSyntax">
81-
<!-- FooSyntax is used here -->
82-
<template bind>
83-
<!-- FooSyntax is used here -->
84-
</template>
85-
<template syntax="OtherSyntax">
86-
<!-- OtherSyntax is used here, NOT FooSyntax -->
87-
</template>
88-
</template>
89-
```
9041
### getBinding
9142

92-
The `getBinding` syntax method allows for a custom interpretation of the contents of mustaches (`{{` ... `}}`).
43+
The `getBinding` method allows for a custom interpretation of the contents of mustaches (`{{` ... `}}`).
9344

9445
When a template is inserting an instance, it will invoke the `getBinding` method (if it is implemented by the syntax) for each mustache which is encountered. The function is invoked with four arguments:
9546

@@ -102,7 +53,7 @@ syntax.getBinding = function(model, path, name, node);
10253
* `name`: The context in which the mustache occurs. Within element attributes, this will be the name of the attribute. Within text, this will be 'textContent'.
10354
* `node`: A reference to the node to which this binding will be created.
10455

105-
If the `getBinding` syntax method wishes to handle binding, it is required to return an object which has at least a `value` property. If it does, then MDV will call
56+
If the `getBinding` method wishes to handle binding, it is required to return an object which has at least a `value` property. If it does, then MDV will call
10657

10758
```JavaScript
10859
node.bind(name, retval, 'value');
@@ -114,7 +65,7 @@ If the 'getBinding' wishes to decline to override, it should not return a value.
11465

11566
### getInstanceModel
11667

117-
The `getInstanceModel` syntax method allows a syntax to provide an alterate model than the one the template would otherwise use when producing an instance.
68+
The `getInstanceModel` method allows a syntax to provide an alterate model than the one the template would otherwise use when producing an instance.
11869

11970
When a template is about to create an instance, it will invoke the `getInstanceModel` method (if it is implemented by the syntax). The function is invoked with two arguments:
12071

@@ -128,7 +79,7 @@ The template element will always use the return value of `getInstanceModel` as t
12879

12980
### CompoundBinding
13081

131-
MDV contains a helper object which is useful for the implementation of a Custom Syntax.
82+
MDV contains a helper object which is useful for the implementation of a Binding Delegate.
13283

13384
```JavaScript
13485
var combinatorFunction = function(values) {

src/template_element.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@
837837
deepCloneIgnoreTemplateContent(content) : content.cloneNode(true);
838838

839839
addMapBindings(instance, map, model, delegate, bound);
840-
// TODO(rafaelw): We can do this more lazily, but setting a sentinal
840+
// TODO(rafaelw): We can do this more lazily, but setting a sentinel
841841
// in the parent of the template element, and creating it when it's
842842
// asked for by walking back to find the iterating template.
843843
addTemplateInstanceRecord(instance, model);
@@ -946,16 +946,13 @@
946946

947947
function newTokenCombinator(tokens) {
948948
return function(values) {
949-
var newValue = '';
949+
var newValue = tokens[0];
950950

951-
for (var i = 0, text = true; i < tokens.length; i++, text = !text) {
952-
if (text) {
953-
newValue += tokens[i];
954-
} else {
955-
var value = values[i];
956-
if (value !== undefined)
957-
newValue += value;
958-
}
951+
for (var i = 1; i < tokens.length; i += 2) {
952+
var value = values[i];
953+
if (value !== undefined)
954+
newValue += value;
955+
newValue += tokens[i + 1];
959956
}
960957

961958
return newValue;
@@ -1277,7 +1274,7 @@
12771274

12781275
if (!this.inputs.size) {
12791276
// End iteration
1280-
templateIteratorTable.delete(this);
1277+
templateIteratorTable.delete(this.templateElement_);
12811278
this.close();
12821279
}
12831280
},

third_party/ChangeSummary

0 commit comments

Comments
 (0)