Skip to content

Commit

Permalink
updated hyper-wire
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giammarchi committed Jan 11, 2019
1 parent d369976 commit 556d74b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cjs/classes/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function setup(content) {
event.component = this;
return (_wire$.dispatchEvent ?
_wire$ :
_wire$.n[0]
_wire$.firstChild
).dispatchEvent(event);
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions cjs/objects/Updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const asNode = (item, i) => {
// all these cases are handled by domdiff already
/* istanbul ignore next */
((1 / i) < 0 ?
(i ? item.remove(true) : item.last) :
(i ? item.valueOf(true) : item.first)) :
(i ? item.remove(true) : item.lastChild) :
(i ? item.valueOf(true) : item.firstChild)) :
asNode(item.render(), i));
}

Expand Down
6 changes: 3 additions & 3 deletions esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion esm/classes/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function setup(content) {
event.component = this;
return (_wire$.dispatchEvent ?
_wire$ :
_wire$.n[0]
_wire$.firstChild
).dispatchEvent(event);
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions esm/objects/Updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const asNode = (item, i) => {
// all these cases are handled by domdiff already
/* istanbul ignore next */
((1 / i) < 0 ?
(i ? item.remove(true) : item.last) :
(i ? item.valueOf(true) : item.first)) :
(i ? item.remove(true) : item.lastChild) :
(i ? item.valueOf(true) : item.firstChild)) :
asNode(item.render(), i));
}

Expand Down
39 changes: 19 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ var hyperHTML = (function (document) {
detail: detail
});
event.component = this;
return (_wire$.dispatchEvent ? _wire$ : _wire$.n[0]).dispatchEvent(event);
return (_wire$.dispatchEvent ? _wire$ : _wire$.firstChild).dispatchEvent(event);
}

return false;
Expand Down Expand Up @@ -1280,15 +1280,15 @@ var hyperHTML = (function (document) {
proto = Wire.prototype;

proto.remove = function (keepFirst) {
var childNodes = this.n;
var first = this.first;
var last = this.last;
this.f = null;
var childNodes = this.childNodes;
var first = this.firstChild;
var last = this.lastChild;
this._ = null;

if (keepFirst && childNodes.length === 2) {
last.parentNode.removeChild(last);
} else {
var range = this.d.createRange();
var range = this.ownerDocument.createRange();
range.setStartBefore(keepFirst ? childNodes[1] : first);
range.setEndAfter(last);
range.deleteContents();
Expand All @@ -1298,28 +1298,27 @@ var hyperHTML = (function (document) {
};

proto.valueOf = function (forceAppend) {
var frag = this.f;
var noFrag = frag == null;
if (noFrag) frag = this.f = this.d.createDocumentFragment();
var fragment = this._;
var noFragment = fragment == null;
if (noFragment) fragment = this._ = this.ownerDocument.createDocumentFragment();

if (noFrag || forceAppend) {
for (var n = this.n, i = 0, l = n.length; i < l; i++) {
frag.appendChild(n[i]);
if (noFragment || forceAppend) {
for (var n = this.childNodes, i = 0, l = n.length; i < l; i++) {
fragment.appendChild(n[i]);
}
}

return frag;
return fragment;
};

return Wire;

function Wire(childNodes) {
var nodes = this.n = slice.call(childNodes, 0);
var first = nodes[0];
this.first = first;
this.last = nodes[nodes.length - 1];
this.d = first.ownerDocument || first;
this.f = null;
var nodes = this.childNodes = slice.call(childNodes, 0);
this.firstChild = nodes[0];
this.lastChild = nodes[nodes.length - 1];
this.ownerDocument = nodes[0].ownerDocument;
this._ = null;
}
}([].slice);

Expand Down Expand Up @@ -1388,7 +1387,7 @@ var hyperHTML = (function (document) {
// all these cases are handled by domdiff already

/* istanbul ignore next */
1 / i < 0 ? i ? item.remove(true) : item.last : i ? item.valueOf(true) : item.first : asNode(item.render(), i);
1 / i < 0 ? i ? item.remove(true) : item.lastChild : i ? item.valueOf(true) : item.firstChild : asNode(item.render(), i);
}; // returns true if domdiff can handle the value


Expand Down
6 changes: 3 additions & 3 deletions min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"domdiff": "^2.0.2",
"domtagger": "^0.2.3",
"hyperhtml-style": "^0.1.2",
"hyperhtml-wire": "^1.0.0",
"hyperhtml-wire": "^2.0.0",
"lightercollective": "^0.2.0"
},
"collective": {
Expand Down
4 changes: 2 additions & 2 deletions test/ie/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,9 @@
return render(_templateObject11());
};

node = update().n;
node = update().childNodes;
tressa.assert(Array.isArray(node), 'list of nodes');
same = update().n;
same = update().childNodes;
tressa.assert(node.length === same.length && node[0] && node.every(function (n, i) {
return same[i] === n;
}), 'same list returned');
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ tressa.async(function (done) {
<p>1</p>
`;
};
node = update().n;
node = update().childNodes;
tressa.assert(Array.isArray(node), 'list of nodes');
same = update().n;
same = update().childNodes;
tressa.assert(
node.length === same.length &&
node[0] &&
Expand Down
6 changes: 3 additions & 3 deletions umd.js

Large diffs are not rendered by default.

0 comments on commit 556d74b

Please sign in to comment.