From dd1302cffc64cc463aec8de8d7f30531de0402b6 Mon Sep 17 00:00:00 2001 From: Ilkka Huotari Date: Sat, 18 Oct 2014 07:48:58 +0000 Subject: [PATCH 1/3] don't add comments when unbound --- index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 4f640ee..7d40a49 100644 --- a/index.js +++ b/index.js @@ -356,15 +356,19 @@ DynamicHtml.prototype.get = function(context) { return this.stringify(value); }; DynamicHtml.prototype.appendTo = function(parent, context, binding) { - var start = document.createComment(this.expression); - var end = document.createComment(this.ending); + if (this.expression.meta.bindType !== 'unbound') { + var start = document.createComment(this.expression); + var end = document.createComment(this.ending); + } var value = getUnescapedValue(this.expression, context); var html = this.stringify(value); var fragment = createHtmlFragment(parent, html); - parent.appendChild(start); + if (this.expression.meta.bindType !== 'unbound') parent.appendChild(start); parent.appendChild(fragment); - parent.appendChild(end); - updateRange(context, binding, this, start, end); + if (this.expression.meta.bindType !== 'unbound') { + parent.appendChild(end); + updateRange(context, binding, this, start, end); + } }; DynamicHtml.prototype.attachTo = function(parent, node, context) { var start = document.createComment(this.expression); From e1f4081a56b0ba737100a04679fbed2c7e55acf4 Mon Sep 17 00:00:00 2001 From: Ilkka Huotari Date: Sat, 18 Oct 2014 12:46:34 +0000 Subject: [PATCH 2/3] some improvement... server side rendering still lacking --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7d40a49..d6ca71a 100644 --- a/index.js +++ b/index.js @@ -356,16 +356,17 @@ DynamicHtml.prototype.get = function(context) { return this.stringify(value); }; DynamicHtml.prototype.appendTo = function(parent, context, binding) { - if (this.expression.meta.bindType !== 'unbound') { + var bound = this.expression.meta.bindType !== 'unbound'; + if (bound) { var start = document.createComment(this.expression); var end = document.createComment(this.ending); } var value = getUnescapedValue(this.expression, context); var html = this.stringify(value); var fragment = createHtmlFragment(parent, html); - if (this.expression.meta.bindType !== 'unbound') parent.appendChild(start); + if (bound) parent.appendChild(start); parent.appendChild(fragment); - if (this.expression.meta.bindType !== 'unbound') { + if (bound) { parent.appendChild(end); updateRange(context, binding, this, start, end); } From 5f0a331fae8fb1352e1bfded1d4f3d4a4a023c98 Mon Sep 17 00:00:00 2001 From: Ilkka Huotari Date: Sat, 18 Oct 2014 13:00:25 +0000 Subject: [PATCH 3/3] server side rendering --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d6ca71a..972110a 100644 --- a/index.js +++ b/index.js @@ -372,14 +372,19 @@ DynamicHtml.prototype.appendTo = function(parent, context, binding) { } }; DynamicHtml.prototype.attachTo = function(parent, node, context) { - var start = document.createComment(this.expression); - var end = document.createComment(this.ending); + var bound = this.expression.meta.bindType !== 'unbound'; + if (bound) { + var start = document.createComment(this.expression); + var end = document.createComment(this.ending); + } var value = getUnescapedValue(this.expression, context); var html = this.stringify(value); - parent.insertBefore(start, node || null); + if (bound) parent.insertBefore(start, node || null); node = attachHtml(parent, node, html); - parent.insertBefore(end, node || null); - updateRange(context, null, this, start, end); + if (bound) { + parent.insertBefore(end, node || null); + updateRange(context, null, this, start, end); + } return node; }; DynamicHtml.prototype.update = function(context, binding) {