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

Commit

Permalink
start on observer, not integrated yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 16, 2014
1 parent 7a3ef92 commit d5dc2f6
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Observer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
*/

(function(scope){

var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
var importSelector = 'link[rel=' + IMPORT_LINK_TYPE + ']';

var importer = scope.importer;

function handler(mutations) {
for (var i=0, l=mutations.length, m; (i<l) && (m=mutations[i]); i++) {
if (m.type === 'childList' && m.addedNodes.length) {
addedNodes(m.addedNodes);
}
});
};

function addedNodes(nodes) {
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) {
if (shouldLoadNode(n)) {
// TODO(sorvell): need to add this api.
importer.addNode(node);
}
}
}

// TODO(sorvell): need x-platform matches
function shouldLoadNode(node) {
return node.matches(importer.preloadSelectors);
}

var observer = new MutationObserver(handler);

function observe(root) {
observer.observe(root, {childList: true, subtree: true});
}

// *****
// TODO(sorvell): wip
function canParse(node) {
var doc = node.ownerDocument;
return nextImportToParse(doc) === node;
}

function nextImportToParse(doc) {

}


// exports
scope.observe = observe;

})(HTMLImports);

0 comments on commit d5dc2f6

Please sign in to comment.