Skip to content

Commit 5ad06c6

Browse files
committed
Some methods that are break the chaining fixed
1 parent 6ab711c commit 5ad06c6

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

src/attr.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
_.extend.attr = function (attr, value) {
66
if (value) {
7-
return this.el.forEach(item => item[attr] = value);
7+
this.el.forEach(item => item[attr] = value);
8+
9+
return this;
810
}
911

1012
return this.el[0][attr];

src/css.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ _.extend.css = function (prop, value) {
5353
options = maybePropIsObject(prop) || options;
5454

5555
if (options.values.length > 0) {
56-
return this.el.map(item => options.properties.forEach((p, i) => item.style[p] = options.values[i]));
56+
this.el.map(item => options.properties.forEach((p, i) => item.style[p] = options.values[i]));
57+
58+
return this;
5759
}
5860

5961
// if no value set then we are asking for getting the values of properties

src/data.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ _.extend.data = function (name, value) {
1313
return this;
1414
}
1515

16-
else {
17-
return item.dataset[domName];
18-
}
16+
return item.dataset[domName];
1917
};

src/manipulation.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,48 @@
66
/* global insertBefore */
77

88
_.extend.empty = function () {
9-
return this.el.forEach(item => item.innerHTML = '');
9+
this.el.forEach(item => item.innerHTML = '');
10+
11+
return this;
1012
};
1113

1214
_.extend.remove = function () {
13-
return this.el.forEach(item => item.parentNode.removeChild(item));
15+
this.el.forEach(item => item.parentNode.removeChild(item));
16+
17+
return this;
1418
};
1519

1620
_.extend.append = function (stringOrObject) {
17-
return this.el.forEach(item => item.appendChild(getInsertableElement(stringOrObject)));
21+
this.el.forEach(item => item.appendChild(getInsertableElement(stringOrObject)));
22+
23+
return this;
1824
};
1925

2026
_.extend.prepend = function (stringOrObject) {
21-
return this.el.forEach(
27+
this.el.forEach(
2228
item => insertBefore(stringOrObject, item, 'firstChild', false));
29+
30+
return this;
2331
};
2432

2533
_.extend.after = function (stringOrObject) {
26-
return this.el.forEach(
34+
this.el.forEach(
2735
item => insertBefore(stringOrObject, item, 'nextSibling', true));
36+
37+
return this;
2838
};
2939

3040
_.extend.before = function (stringOrObject) {
31-
return this.el.forEach(
41+
this.el.forEach(
3242
item => insertBefore(stringOrObject, item, 'self', true));
43+
44+
return this;
3345
};
3446

3547
_.extend.replaceWith = function (stringOrObject) {
36-
return this.el.map(
48+
this.el.map(
3749
item => item.parentNode.replaceChild(getInsertableElement(stringOrObject), item)
3850
);
51+
52+
return this;
3953
};

test/wrap-test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('Element Wrapping', () => {
3131

3232
let newParent = single['0'].parentNode;
3333

34-
expect(firstParent.matches('#wrap')).to.be.true;
35-
expect(newParent.matches('#wrap')).to.be.false;
34+
expect(firstParent.matches('#wrap')).to.be.equal(true);
35+
expect(newParent.matches('#wrap')).to.be.equal(false);
3636
});
3737

3838
it('should wrap and replace child if the element is the only child', () => {
@@ -42,14 +42,13 @@ describe('Element Wrapping', () => {
4242

4343
singleInner.wrap('<div />');
4444

45-
let newParent = singleInner['0'].parentNode;
4645
let newLength = parent.childNodes.length;
4746
let newChild = parent.firstChild.classList.contains('wrap-single-inner');
4847

4948
expect(length).to.be.equal(1);
50-
expect(child).to.be.true;
49+
expect(child).to.be.equal(true);
5150
expect(newLength).to.be.equal(1);
52-
expect(newChild).to.be.false;
51+
expect(newChild).to.be.equal(false);
5352
});
5453

5554
it('should wrap element with "div" has a class value "new-wrap" and id value "wrap-id"', () => {
@@ -59,9 +58,9 @@ describe('Element Wrapping', () => {
5958

6059
let newParent = singleAttr['0'].parentNode;
6160

62-
expect(firstParent.matches('#wrap')).to.be.true;
63-
expect(newParent.matches('#wrap-id')).to.be.true;
64-
expect(newParent.classList.contains('new-wrap')).to.be.true;
61+
expect(firstParent.matches('#wrap')).to.be.equal(true);
62+
expect(newParent.matches('#wrap-id')).to.be.equal(true);
63+
expect(newParent.classList.contains('new-wrap')).to.be.equal(true);
6564
});
6665
});
6766

0 commit comments

Comments
 (0)