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

Commit

Permalink
Updating enterView/leaveView callbacks to apply only to primary docum…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
blois committed Sep 13, 2013
1 parent 57e4d9c commit 32ef207
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ license that can be found in the LICENSE file.

var logFlags = window.logFlags || {};

// walk the subtree rooted at node, applying 'find(element, data)' function
// walk the subtree rooted at node, applying 'find(element, data)' function
// to each element
// if 'find' returns true for 'element', do not search element's subtree
// if 'find' returns true for 'element', do not search element's subtree
function findAll(node, find, data) {
var e = node.firstElementChild;
if (!e) {
Expand All @@ -37,7 +37,7 @@ function forRoots(node, cb) {
}
}

// walk the subtree rooted at node, including descent into shadow-roots,
// walk the subtree rooted at node, including descent into shadow-roots,
// applying 'cb' to each element
function forSubtree(node, cb) {
//logFlags.dom && node.childNodes && node.childNodes.length && console.group('subTree: ', node);
Expand All @@ -55,7 +55,7 @@ function forSubtree(node, cb) {
function added(node) {
if (upgrade(node)) {
insertedNode(node);
return true;
return true;
}
inserted(node);
}
Expand All @@ -64,7 +64,7 @@ function added(node) {
function addedSubtree(node) {
forSubtree(node, function(e) {
if (added(e)) {
return true;
return true;
}
});
}
Expand Down Expand Up @@ -162,8 +162,10 @@ function removed(element) {

function inDocument(element) {
var p = element;
var doc = window.ShadowDOMPolyfill &&
window.ShadowDOMPolyfill.wrapIfNeeded(document) || document;
while (p) {
if (p == element.ownerDocument) {
if (p == doc) {
return true;
}
p = p.parentNode || p.host;
Expand Down
35 changes: 35 additions & 0 deletions test/js/customElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,41 @@
assert(xboo2.__ready__, 'clone createdCallback must be called');
done();
});

test('entered left apply to view', function() {
var invocations = [];
var elementProto = Object.create(HTMLElement.prototype);
elementProto.createdCallback = function() {
invocations.push('created');
}
elementProto.enteredViewCallback = function() {
invocations.push('entered');
}
elementProto.leftViewCallback = function() {
invocations.push('left');
}
var tagName = 'x-entered-left-view';
var CustomElement = document.register(tagName, { prototype: elementProto });

var docB = document.implementation.createHTMLDocument('');
docB.body.innerHTML = '<' + tagName + '></' + tagName + '>';
CustomElements.upgradeAll(docB);
CustomElements.takeRecords();
assert.deepEqual(invocations, ['created'], 'created but not entered view');

var element = docB.body.childNodes[0];
assert.instanceOf(element, CustomElement, 'element is correct type');

work.appendChild(element)
CustomElements.takeRecords();
assert.deepEqual(invocations, ['created', 'entered'],
'created and entered view');

docB.body.appendChild(element);
CustomElements.takeRecords();
assert.deepEqual(invocations, ['created', 'entered', 'left'],
'created, entered then left view');
});
});

htmlSuite('customElements (html)', function() {
Expand Down

0 comments on commit 32ef207

Please sign in to comment.