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

Commit

Permalink
by default, install template syntax once.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 11, 2014
1 parent dccc3fe commit 880c47b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 31 deletions.
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"src/declaration/events.js",
"src/declaration/properties.js",
"src/declaration/attributes.js",
"src/declaration/mdv.js",
"src/declaration/prototype.js",
"src/declaration/queue.js",
"src/declaration/import.js",
Expand Down
1 change: 1 addition & 0 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="src/declaration/events.js"></script>
<script src="src/declaration/properties.js"></script>
<script src="src/declaration/attributes.js"></script>
<script src="src/declaration/mdv.js"></script>
<script src="src/declaration/prototype.js"></script>
<script src="src/declaration/queue.js"></script>
<script src="src/declaration/import.js"></script>
Expand Down
54 changes: 54 additions & 0 deletions src/declaration/mdv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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) {

// imports

var syntax = new PolymerExpressions();
syntax.resolveEventHandler = function(model, path, node) {
var ctlr = findEventController(node);
if (ctlr) {
var fn = path.getValueFrom(ctlr);
if (fn) {
return fn.bind(ctlr);
}
}
};

// An event controller is the host element for the shadowRoot in which
// the node exists, or the first ancestor with a 'lightDomController'
// property.
function findEventController(node) {
while (node.parentNode) {
if (node.lightDomController) {
return node;
}
node = node.parentNode;
}
return node.host;
}

// declaration api supporting mdv
var mdv = {
syntax: syntax,
fetchTemplate: function() {
return this.querySelector('template');
},
templateContent: function() {
var template = this.fetchTemplate();
return template && templateContent(template);
},
installBindingDelegate: function(template) {
if (template) {
template.bindingDelegate = this.syntax;
}
}
};

// exports
scope.api.declaration.mdv = mdv;

})(Polymer);
2 changes: 2 additions & 0 deletions src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
// build side-chained lists to optimize iterations
this.optimizePropertyMaps(this.prototype);
this.createPropertyAccessors(this.prototype);
// install mdv delegate on template
this.installBindingDelegate(this.fetchTemplate());
// install external stylesheets as if they are inline
this.installSheets();
// adjust any paths in dom from imports
Expand Down
4 changes: 0 additions & 4 deletions src/declaration/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@
}
return matcher ? nodes.filter(matcher) : nodes;
},
templateContent: function() {
var template = this.querySelector('template');
return template && templateContent(template);
},
/**
* Promotes external stylesheets and <style> elements with the attribute
* polymer-scope='global' into global scope.
Expand Down
28 changes: 1 addition & 27 deletions src/instance/mdv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,10 @@
// imports

var log = window.logFlags || 0;
var events = scope.api.instance.events;

var syntax = new PolymerExpressions();
syntax.resolveEventHandler = function(model, path, node) {
var ctlr = findEventController(node);
if (ctlr) {
var fn = path.getValueFrom(ctlr);
if (fn) {
return fn.bind(ctlr);
}
}
}

// An event controller is the host element for the shadowRoot in which
// the node exists, or the first ancestor with a 'lightDomController'
// property.
function findEventController(node) {
while (node.parentNode) {
if (node.lightDomController) {
return node;
}
node = node.parentNode;
}
return node.host;
};

// element api supporting mdv

var mdv = {
syntax: syntax,
//syntax: syntax,
instanceTemplate: function(template) {
var dom = template.createInstance(this, this.syntax);
this.registerObservers(dom.bindings_);
Expand Down
1 change: 1 addition & 0 deletions src/polymer-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
modelName: 'model',

ready: function() {
this.syntax = this.element.syntax;
this.template = document.querySelector('template');
var model = window[this.modelName];
if (model) {
Expand Down

0 comments on commit 880c47b

Please sign in to comment.