Permalink
Browse files

feat(Fragment): Added Fragment class for directives

  • Loading branch information...
calebdwilliams committed Feb 16, 2018
1 parent f564135 commit 1dd85e1d1ea2d782d0d93234157ba068c144c660
@@ -54,10 +54,11 @@ class AttributeNode {
this.compiler = compiler;
this.boundAttrs.forEach(attribute => {
attribute.base = attribute.value;
this.indicies = attribute.base.match(valuePattern).map(index => +index.replace(startSeparator, '').replace(endSeparator, ''));
const bases = attribute.base.match(valuePattern) || [];
this.indicies = bases.map(index => +index.replace(startSeparator, '').replace(endSeparator, ''));
this.indicies.forEach(index => this.compiler.partIndicies.set(index, this));
});

this.addListeners();
}

@@ -82,7 +83,7 @@ class AttributeNode {
const attributeName = attribute.name.replace(/\[|\]/g, '');
this.node[attributeName] = attributeValue;
if (attributeValue && attributeValue !== 'false') {
this.node.setAttribute(attributeName, attributeValue);
this.node.setAttribute(attributeName, attributeValue);
} else {
this.node.removeAttribute(attributeName);
}
@@ -102,7 +103,7 @@ class AttributeNode {
attributeValue = attributeValue.replace(`---!{${baseIndicies[i]}}!---`, value);
}
}

attribute.value = attributeValue;
if (attribute.name.match(propPattern)) {
if (baseIndicies.length === 1) {
@@ -114,21 +115,21 @@ class AttributeNode {
}
}

class Template {
class Fragment {
constructor(strings, values, location, context) {
this.strings = strings;
this.values = values;
this.oldValues = values.map((value, index) => `---!{${index}}!---`);
this.location = location;
this.context = context;
this.location = location;
this.parts = [];
this.partIndicies = new Map();

this.eventHandlers = [];
this._init();
}

_append(node) {
_setParts() {
for (let i = 0; i < this.parts.length; i += 1) {
const part = this.parts[i];
if (part instanceof ContentNode) {
@@ -138,7 +139,7 @@ class Template {
}
}

this.location.appendChild(node);
// this.location.appendChild(node);
}

_init() {
@@ -151,7 +152,7 @@ class Template {

const walker = document.createTreeWalker(baseNode, 133, null, false);
this._walk(walker, this.parts, true);
this._append(baseNode);
this._setParts(baseNode);
}

_walk(walker, parts, setup) {
@@ -208,6 +209,17 @@ class Template {
}
}

class Template extends Fragment {
constructor(strings, values, location, context) {
super(strings, values, location, context);
}

_setParts(node) {
super._setParts();
this.location.appendChild(node);
}
}

const templateCache = new WeakMap();

function templiteral(location = this, context = this) {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -50,10 +50,11 @@ class AttributeNode {
this.compiler = compiler;
this.boundAttrs.forEach(attribute => {
attribute.base = attribute.value;
this.indicies = attribute.base.match(valuePattern).map(index => +index.replace(startSeparator, '').replace(endSeparator, ''));
const bases = attribute.base.match(valuePattern) || [];
this.indicies = bases.map(index => +index.replace(startSeparator, '').replace(endSeparator, ''));
this.indicies.forEach(index => this.compiler.partIndicies.set(index, this));
});

this.addListeners();
}

@@ -78,7 +79,7 @@ class AttributeNode {
const attributeName = attribute.name.replace(/\[|\]/g, '');
this.node[attributeName] = attributeValue;
if (attributeValue && attributeValue !== 'false') {
this.node.setAttribute(attributeName, attributeValue);
this.node.setAttribute(attributeName, attributeValue);
} else {
this.node.removeAttribute(attributeName);
}
@@ -98,7 +99,7 @@ class AttributeNode {
attributeValue = attributeValue.replace(`---!{${baseIndicies[i]}}!---`, value);
}
}

attribute.value = attributeValue;
if (attribute.name.match(propPattern)) {
if (baseIndicies.length === 1) {
@@ -110,21 +111,21 @@ class AttributeNode {
}
}

class Template {
class Fragment {
constructor(strings, values, location, context) {
this.strings = strings;
this.values = values;
this.oldValues = values.map((value, index) => `---!{${index}}!---`);
this.location = location;
this.context = context;
this.location = location;
this.parts = [];
this.partIndicies = new Map();

this.eventHandlers = [];
this._init();
}

_append(node) {
_setParts() {
for (let i = 0; i < this.parts.length; i += 1) {
const part = this.parts[i];
if (part instanceof ContentNode) {
@@ -134,7 +135,7 @@ class Template {
}
}

this.location.appendChild(node);
// this.location.appendChild(node);
}

_init() {
@@ -147,7 +148,7 @@ class Template {

const walker = document.createTreeWalker(baseNode, 133, null, false);
this._walk(walker, this.parts, true);
this._append(baseNode);
this._setParts(baseNode);
}

_walk(walker, parts, setup) {
@@ -204,6 +205,17 @@ class Template {
}
}

class Template extends Fragment {
constructor(strings, values, location, context) {
super(strings, values, location, context);
}

_setParts(node) {
super._setParts();
this.location.appendChild(node);
}
}

const templateCache = new WeakMap();

function templiteral(location = this, context = this) {
Oops, something went wrong.

0 comments on commit 1dd85e1

Please sign in to comment.