|
103 | 103 | }; |
104 | 104 | } |
105 | 105 |
|
106 | | - Text.prototype.bind = function(name, observable) { |
| 106 | + Text.prototype.bind = function(name, value, oneTime) { |
107 | 107 | if (name !== 'textContent') |
108 | | - return Node.prototype.bind.call(this, name, observable); |
| 108 | + return Node.prototype.bind.call(this, name, value, oneTime); |
| 109 | + |
| 110 | + if (oneTime) |
| 111 | + return updateText(this, value); |
109 | 112 |
|
110 | 113 | unbind(this, 'textContent'); |
111 | | - updateText(this, observable.open(textBinding(this))); |
112 | | - return this.bindings.textContent = observable; |
| 114 | + updateText(this, value.open(textBinding(this))); |
| 115 | + return this.bindings.textContent = value; |
113 | 116 | } |
114 | 117 |
|
115 | 118 | function updateAttribute(el, name, conditional, value) { |
|
130 | 133 | }; |
131 | 134 | } |
132 | 135 |
|
133 | | - Element.prototype.bind = function(name, observable) { |
| 136 | + Element.prototype.bind = function(name, value, oneTime) { |
134 | 137 | var conditional = name[name.length - 1] == '?'; |
135 | 138 | if (conditional) { |
136 | 139 | this.removeAttribute(name); |
137 | 140 | name = name.slice(0, -1); |
138 | 141 | } |
139 | 142 |
|
140 | | - unbind(this, name); |
| 143 | + if (oneTime) |
| 144 | + return updateAttribute(this, name, conditional, value); |
141 | 145 |
|
| 146 | + unbind(this, name); |
142 | 147 | updateAttribute(this, name, conditional, |
143 | | - observable.open(attributeBinding(this, name, conditional))); |
| 148 | + value.open(attributeBinding(this, name, conditional))); |
144 | 149 |
|
145 | | - return this.bindings[name] = observable; |
| 150 | + return this.bindings[name] = value; |
146 | 151 | }; |
147 | 152 |
|
148 | 153 | var checkboxEventType; |
|
269 | 274 | } |
270 | 275 | } |
271 | 276 |
|
272 | | - HTMLInputElement.prototype.bind = function(name, observable) { |
| 277 | + HTMLInputElement.prototype.bind = function(name, value, oneTime) { |
273 | 278 | if (name !== 'value' && name !== 'checked') |
274 | | - return HTMLElement.prototype.bind.call(this, name, observable); |
| 279 | + return HTMLElement.prototype.bind.call(this, name, value, oneTime); |
275 | 280 |
|
276 | | - unbind(this, name); |
277 | | - this.removeAttribute(name); |
278 | 281 |
|
| 282 | + this.removeAttribute(name); |
279 | 283 | var sanitizeFn = name == 'checked' ? booleanSanitize : sanitizeValue; |
280 | 284 | var postEventFn = name == 'checked' ? checkedPostEvent : noop; |
281 | | - bindInputEvent(this, name, observable, postEventFn); |
| 285 | + |
| 286 | + if (oneTime) |
| 287 | + return updateInput(this, name, value, sanitizeFn); |
| 288 | + |
| 289 | + unbind(this, name); |
| 290 | + bindInputEvent(this, name, value, postEventFn); |
282 | 291 | updateInput(this, name, |
283 | | - observable.open(inputBinding(this, name, sanitizeFn)), |
| 292 | + value.open(inputBinding(this, name, sanitizeFn)), |
284 | 293 | sanitizeFn); |
285 | 294 |
|
286 | | - return this.bindings[name] = observable; |
| 295 | + return this.bindings[name] = value; |
287 | 296 | } |
288 | 297 |
|
289 | | - HTMLTextAreaElement.prototype.bind = function(name, observable) { |
| 298 | + HTMLTextAreaElement.prototype.bind = function(name, value, oneTime) { |
290 | 299 | if (name !== 'value') |
291 | | - return HTMLElement.prototype.bind.call(this, name, observable); |
| 300 | + return HTMLElement.prototype.bind.call(this, name, value, oneTime); |
292 | 301 |
|
293 | | - unbind(this, 'value'); |
294 | 302 | this.removeAttribute('value'); |
295 | 303 |
|
296 | | - bindInputEvent(this, 'value', observable); |
| 304 | + if (oneTime) |
| 305 | + return updateInput(this, 'value', value); |
| 306 | + |
| 307 | + unbind(this, 'value'); |
| 308 | + bindInputEvent(this, 'value', value); |
297 | 309 | updateInput(this, 'value', |
298 | | - observable.open(inputBinding(this, 'value', sanitizeValue))); |
| 310 | + value.open(inputBinding(this, 'value', sanitizeValue))); |
299 | 311 |
|
300 | | - return this.bindings.value = observable; |
| 312 | + return this.bindings.value = value; |
301 | 313 | } |
302 | 314 |
|
303 | 315 | function updateOption(option, value) { |
|
326 | 338 | } |
327 | 339 | } |
328 | 340 |
|
329 | | - HTMLOptionElement.prototype.bind = function(name, observable) { |
| 341 | + HTMLOptionElement.prototype.bind = function(name, value, oneTime) { |
330 | 342 | if (name !== 'value') |
331 | | - return HTMLElement.prototype.bind.call(this, name, observable); |
| 343 | + return HTMLElement.prototype.bind.call(this, name, value, oneTime); |
332 | 344 |
|
333 | | - unbind(this, 'value'); |
334 | 345 | this.removeAttribute('value'); |
335 | 346 |
|
336 | | - bindInputEvent(this, 'value', observable); |
337 | | - updateOption(this, observable.open(optionBinding(this))); |
338 | | - return this.bindings.value = observable; |
| 347 | + if (oneTime) |
| 348 | + return updateOption(this, value); |
| 349 | + |
| 350 | + unbind(this, 'value'); |
| 351 | + bindInputEvent(this, 'value', value); |
| 352 | + updateOption(this, value.open(optionBinding(this))); |
| 353 | + return this.bindings.value = value; |
339 | 354 | } |
340 | 355 |
|
341 | 356 | function updateSelect(select, property, value, retries) { |
|
356 | 371 | } |
357 | 372 | } |
358 | 373 |
|
359 | | - HTMLSelectElement.prototype.bind = function(name, observable) { |
| 374 | + HTMLSelectElement.prototype.bind = function(name, value, oneTime) { |
360 | 375 | if (name === 'selectedindex') |
361 | 376 | name = 'selectedIndex'; |
362 | 377 |
|
363 | 378 | if (name !== 'selectedIndex' && name !== 'value') |
364 | | - return HTMLElement.prototype.bind.call(this, name, observable); |
| 379 | + return HTMLElement.prototype.bind.call(this, name, value, oneTime); |
365 | 380 |
|
366 | | - |
367 | | - unbind(this, name); |
368 | 381 | this.removeAttribute(name); |
369 | 382 |
|
370 | | - bindInputEvent(this, name, observable); |
371 | | - updateSelect(this, name, observable.open(selectBinding(this, name)), 2); |
372 | | - return this.bindings[name] = observable; |
| 383 | + if (oneTime) |
| 384 | + return updateSelect(this, name, value); |
| 385 | + |
| 386 | + unbind(this, name); |
| 387 | + bindInputEvent(this, name, value); |
| 388 | + updateSelect(this, name, value.open(selectBinding(this, name)), 2); |
| 389 | + return this.bindings[name] = value; |
373 | 390 | } |
374 | 391 |
|
375 | 392 | // TODO(rafaelw): We should polyfill a Microtask Promise and define it if it isn't. |
|
0 commit comments