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

Commit

Permalink
make ref private API
Browse files Browse the repository at this point in the history
This patch is the first step towards making ref resolve the first time that an instance is produced, but allowing dynamic tracking of ref by all instances (including binding to ref).

R=arv
BUG=

Review URL: https://codereview.appspot.com/60640045
  • Loading branch information
rafaelw committed Feb 6, 2014
1 parent b78a841 commit ef5535a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
if (bindingDelegate)
delegate_ = this.newDelegate_(bindingDelegate);

var content = this.ref.content;
var content = this.ref_.content;
var map = this.bindingMap_;
if (!map || map.content !== content) {
// TODO(rafaelw): Setup a MutationObserver on content to detect
Expand Down Expand Up @@ -565,15 +565,15 @@
this.setDelegate_(this.newDelegate_(bindingDelegate));
},

get ref() {
get ref_() {
var ref = searchRefId(this, this.getAttribute('ref'));
if (!ref)
ref = this.instanceRef_;

if (!ref)
return this;

var nextRef = ref.ref;
var nextRef = ref.ref_;
return nextRef ? nextRef : ref;
}
});
Expand Down
19 changes: 9 additions & 10 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,6 @@ suite('Template Instantiation', function() {
var t1 = div.firstChild;
var t2 = div.childNodes[1];

assert.strictEqual(t1, t2.ref);

var model = {name: 'Fry'};
t2.model = model;

Expand Down Expand Up @@ -2040,7 +2038,6 @@ suite('Template Instantiation', function() {
assert.strictEqual(2, select.childNodes.length);
assert.strictEqual(1, select.selectedIndex);
assert.strictEqual('TEMPLATE', select.childNodes[0].tagName);
assert.strictEqual('OPTGROUP', select.childNodes[0].ref.content.firstChild.tagName);
var optgroup = select.childNodes[1];
assert.strictEqual('TEMPLATE', optgroup.childNodes[0].tagName);
assert.strictEqual('OPTION', optgroup.childNodes[1].tagName);
Expand Down Expand Up @@ -2669,7 +2666,6 @@ suite('Template Instantiation', function() {
};

var instance = outer.createInstance(model, delegate);
assert.strictEqual(instance.firstChild.ref, outer.content.firstChild);
assert.strictEqual('bar:replaced',
instance.firstChild.nextSibling.textContent);
unbindAll(instance);
Expand Down Expand Up @@ -3232,15 +3228,18 @@ suite('Binding Delegate API', function() {
});
});

test('issue-152', function() {
test('issue-152', function(done) {
var div = createTestHtml(
'<template ref=notThere></template>');
'<template ref=notThere bind>XXX</template>');

var template = div.firstChild;

// if a ref cannot be located, a template will continue to use itself
// as the source of template instances.
assert.strictEqual(template, template.ref);
template.model = {};
then(function() {
// if a ref cannot be located, a template will continue to use itself
// as the source of template instances.
assert.strictEqual('XXX', div.childNodes[1].textContent);
done();
})
});
});

Expand Down

0 comments on commit ef5535a

Please sign in to comment.