Skip to content

Commit b581c84

Browse files
committed
Move CompoundPath#reduce() to Item#reduce().
1 parent c0c5695 commit b581c84

3 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/item/Item.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,23 @@ var Item = Base.extend(Callback, /** @lends Item# */{
17411741
*/
17421742
moveBelow: '#insertBelow',
17431743

1744+
/**
1745+
* If this is a group, layer or compound-path with only one child-item,
1746+
* the child-item is moved outside and the parent is erased. Otherwise, the
1747+
* item itself is returned unmodified.
1748+
*
1749+
* @return {Item} the reduced item
1750+
*/
1751+
reduce: function() {
1752+
if (this._children && this._children.length === 1) {
1753+
var child = this._children[0];
1754+
child.insertAbove(this);
1755+
this.remove();
1756+
return child;
1757+
}
1758+
return this;
1759+
},
1760+
17441761
/**
17451762
* Removes the item from its parent's named children list.
17461763
*/

src/path/CompoundPath.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
7373
return items;
7474
},
7575

76-
/**
77-
* If this is a compound path with only one path inside,
78-
* the path is moved outside and the compound path is erased.
79-
* Otherwise, the compound path is returned unmodified.
80-
*
81-
* @return {CompoundPath|Path} the flattened compound path
82-
*/
83-
reduce: function() {
84-
if (this._children.length == 1) {
85-
var child = this._children[0];
86-
child.insertAbove(this);
87-
this.remove();
88-
return child;
89-
}
90-
return this;
91-
},
92-
9376
/**
9477
* Reverses the orientation of all nested paths.
9578
*/

src/path/Path.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,6 @@ var Path = PathItem.extend(/** @lends Path# */{
12291229
return false;
12301230
},
12311231

1232-
/**
1233-
* For simple paths, reduce always returns the path itself. See
1234-
* {@link CompoundPath#reduce()} for more explanations.
1235-
*/
1236-
reduce: function() {
1237-
return this;
1238-
},
1239-
12401232
/**
12411233
* The approximate length of the path in points.
12421234
*

0 commit comments

Comments
 (0)