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

Commit 82a032a

Browse files
committed
Remove async hack for select binding (and ensureScheduled which is no longer needed).
R=arv BUG= Review URL: https://codereview.appspot.com/45780044
1 parent 5030c46 commit 82a032a

2 files changed

Lines changed: 5 additions & 98 deletions

File tree

src/NodeBind.js

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,6 @@
394394
return this.bindings.value = value;
395395
}
396396

397-
function updateSelect(select, property, value, retries) {
398-
select[property] = value;
399-
if (!retries || select[property] == value)
400-
return
401-
402-
// The binding may wish to bind to an <option> which has not yet been
403-
// produced by a child <template>. Delay |retries| times.
404-
ensureScheduled(function() {
405-
updateSelect(select, property, value, retries - 1);
406-
});
407-
}
408-
409-
function selectBinding(select, property) {
410-
return function(value) {
411-
updateSelect(select, property, value);
412-
}
413-
}
414-
415397
HTMLSelectElement.prototype.bind = function(name, value, oneTime) {
416398
if (name === 'selectedindex')
417399
name = 'selectedIndex';
@@ -422,87 +404,12 @@
422404
this.removeAttribute(name);
423405

424406
if (oneTime)
425-
return updateSelect(this, name, value);
407+
return updateInput(this, name, value);
426408

427409
unbind(this, name);
428410
bindInputEvent(this, name, value);
429-
updateSelect(this, name, value.open(selectBinding(this, name)), 2);
411+
updateInput(this, name,
412+
value.open(inputBinding(this, name)));
430413
return this.bindings[name] = value;
431414
}
432-
433-
// TODO(rafaelw): We should polyfill a Microtask Promise and define it if it isn't.
434-
var ensureScheduled = function() {
435-
// We need to ping-pong between two Runners in order for the tests to
436-
// simulate proper end-of-microtask behavior for Object.observe. Without
437-
// this, we'll continue delivering to a single observer without allowing
438-
// other observers in the same microtask to make progress.
439-
440-
function Runner(nextRunner) {
441-
this.nextRunner = nextRunner;
442-
this.value = false;
443-
this.lastValue = this.value;
444-
this.scheduled = [];
445-
this.scheduledIds = [];
446-
this.running = false;
447-
this.observer = new PathObserver(this, 'value');
448-
this.observer.open(this.run, this);
449-
}
450-
451-
Runner.prototype = {
452-
schedule: function(async, id) {
453-
if (this.scheduledIds[id])
454-
return;
455-
456-
if (this.running)
457-
return this.nextRunner.schedule(async, id);
458-
459-
this.scheduledIds[id] = true;
460-
this.scheduled.push(async);
461-
462-
if (this.lastValue !== this.value)
463-
return;
464-
465-
this.value = !this.value;
466-
},
467-
468-
run: function() {
469-
this.running = true;
470-
471-
for (var i = 0; i < this.scheduled.length; i++) {
472-
var async = this.scheduled[i];
473-
var id = async[idExpando];
474-
this.scheduledIds[id] = false;
475-
476-
if (typeof async === 'function')
477-
async();
478-
else
479-
async.resolve();
480-
}
481-
482-
this.scheduled = [];
483-
this.scheduledIds = [];
484-
this.lastValue = this.value;
485-
486-
this.running = false;
487-
}
488-
}
489-
490-
var runner = new Runner(new Runner());
491-
492-
var nextId = 1;
493-
var idExpando = '__scheduledId__';
494-
495-
function ensureScheduled(async) {
496-
var id = async[idExpando];
497-
if (!async[idExpando]) {
498-
id = nextId++;
499-
async[idExpando] = id;
500-
}
501-
502-
runner.schedule(async, id);
503-
}
504-
505-
return ensureScheduled;
506-
}();
507-
508415
})(this);

tests/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function doTeardown() {
3232
document.body.removeChild(testDiv);
3333
unbindAll(testDiv);
3434
Platform.performMicrotaskCheckpoint();
35-
assert.strictEqual(2, Observer._allObserversCount);
35+
assert.strictEqual(0, Observer._allObserversCount);
3636
}
3737

3838
function dispatchEvent(type, target) {
@@ -90,7 +90,7 @@ suite('Text bindings', function() {
9090
var model = {a: { b: { c: 1}}};
9191
var observer = new PathObserver(model, 'a.b.c');
9292
text.bind('textContent', observer);
93-
assert.strictEqual(3, Observer._allObserversCount);
93+
assert.strictEqual(1, Observer._allObserversCount);
9494
assert.strictEqual('1', text.data);
9595

9696
model.a.b.c = 2;

0 commit comments

Comments
 (0)