Skip to content

Commit c82c509

Browse files
committed
Add optional chaining to event method calls
Replaced direct method calls on event objects with optional chaining to prevent errors if methods are undefined. Updated documentation for the dispose method to clarify its behavior. Updated build artifacts and documentation accordingly.
1 parent 2a02ac9 commit c82c509

File tree

11 files changed

+203
-137
lines changed

11 files changed

+203
-137
lines changed

build/two.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ var Two = (() => {
12201220
* @name Two.PublishDate
12211221
* @property {String} - The automatically generated publish date in the build process to verify version release candidates.
12221222
*/
1223-
PublishDate: "2025-12-05T06:10:07.715Z",
1223+
PublishDate: "2025-12-22T19:56:52.386Z",
12241224
/**
12251225
* @name Two.Identifier
12261226
* @property {String} - String prefix for all Two.js object's ids. This trickles down to SVG ids.
@@ -1785,34 +1785,34 @@ var Two = (() => {
17851785
this.#events._bound = v;
17861786
}
17871787
addEventListener() {
1788-
return this.#events.addEventListener.apply(this, arguments);
1788+
return this.#events.addEventListener?.apply(this, arguments);
17891789
}
17901790
on() {
1791-
return this.#events.on.apply(this, arguments);
1791+
return this.#events.on?.apply(this, arguments);
17921792
}
17931793
bind() {
1794-
return this.#events.bind.apply(this, arguments);
1794+
return this.#events.bind?.apply(this, arguments);
17951795
}
17961796
removeEventListener() {
1797-
return this.#events.removeEventListener.apply(this, arguments);
1797+
return this.#events.removeEventListener?.apply(this, arguments);
17981798
}
17991799
off() {
1800-
return this.#events.off.apply(this, arguments);
1800+
return this.#events.off?.apply(this, arguments);
18011801
}
18021802
unbind() {
1803-
return this.#events.unbind.apply(this, arguments);
1803+
return this.#events.unbind?.apply(this, arguments);
18041804
}
18051805
dispatchEvent() {
1806-
return this.#events.dispatchEvent.apply(this, arguments);
1806+
return this.#events.dispatchEvent?.apply(this, arguments);
18071807
}
18081808
trigger() {
1809-
return this.#events.trigger.apply(this, arguments);
1809+
return this.#events.trigger?.apply(this, arguments);
18101810
}
18111811
listen() {
1812-
return this.#events.listen.apply(this, arguments);
1812+
return this.#events.listen?.apply(this, arguments);
18131813
}
18141814
ignore() {
1815-
return this.#events.ignore.apply(this, arguments);
1815+
return this.#events.ignore?.apply(this, arguments);
18161816
}
18171817
constructor() {
18181818
super();
@@ -4139,8 +4139,7 @@ var Two = (() => {
41394139
/**
41404140
* @name Two.Shape#dispose
41414141
* @function
4142-
* @description Release the element's renderer object and detach any events.
4143-
* This cleans up renderer-specific resources and unbinds all event listeners.
4142+
* @description Release the shape's bound objects by unbinding relevant events.
41444143
*/
41454144
dispose() {
41464145
super.dispose();
@@ -15624,34 +15623,34 @@ var Two = (() => {
1562415623
this._events._bound = v;
1562515624
}
1562615625
addEventListener() {
15627-
return this._events.addEventListener.apply(this, arguments);
15626+
return this._events.addEventListener?.apply(this, arguments);
1562815627
}
1562915628
on() {
15630-
return this._events.addEventListener.apply(this, arguments);
15629+
return this._events.addEventListener?.apply(this, arguments);
1563115630
}
1563215631
bind() {
15633-
return this._events.addEventListener.apply(this, arguments);
15632+
return this._events.addEventListener?.apply(this, arguments);
1563415633
}
1563515634
removeEventListener() {
15636-
return this._events.removeEventListener.apply(this, arguments);
15635+
return this._events.removeEventListener?.apply(this, arguments);
1563715636
}
1563815637
off() {
15639-
return this._events.removeEventListener.apply(this, arguments);
15638+
return this._events.removeEventListener?.apply(this, arguments);
1564015639
}
1564115640
unbind() {
15642-
return this._events.removeEventListener.apply(this, arguments);
15641+
return this._events.removeEventListener?.apply(this, arguments);
1564315642
}
1564415643
dispatchEvent() {
15645-
return this._events.dispatchEvent.apply(this, arguments);
15644+
return this._events.dispatchEvent?.apply(this, arguments);
1564615645
}
1564715646
trigger() {
15648-
return this._events.dispatchEvent.apply(this, arguments);
15647+
return this._events.dispatchEvent?.apply(this, arguments);
1564915648
}
1565015649
listen() {
15651-
return this._events.listen.apply(this, arguments);
15650+
return this._events.listen?.apply(this, arguments);
1565215651
}
1565315652
ignore() {
15654-
return this._events.ignore.apply(this, arguments);
15653+
return this._events.ignore?.apply(this, arguments);
1565515654
}
1565615655
/**
1565715656
* @name Two#type

build/two.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/two.module.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ var Constants = {
12281228
* @name Two.PublishDate
12291229
* @property {String} - The automatically generated publish date in the build process to verify version release candidates.
12301230
*/
1231-
PublishDate: "2025-12-05T06:10:07.715Z",
1231+
PublishDate: "2025-12-22T19:56:52.386Z",
12321232
/**
12331233
* @name Two.Identifier
12341234
* @property {String} - String prefix for all Two.js object's ids. This trickles down to SVG ids.
@@ -1804,34 +1804,44 @@ var Collection = class extends Array {
18041804
__privateGet(this, _events)._bound = v;
18051805
}
18061806
addEventListener() {
1807-
return __privateGet(this, _events).addEventListener.apply(this, arguments);
1807+
var _a;
1808+
return (_a = __privateGet(this, _events).addEventListener) == null ? void 0 : _a.apply(this, arguments);
18081809
}
18091810
on() {
1810-
return __privateGet(this, _events).on.apply(this, arguments);
1811+
var _a;
1812+
return (_a = __privateGet(this, _events).on) == null ? void 0 : _a.apply(this, arguments);
18111813
}
18121814
bind() {
1813-
return __privateGet(this, _events).bind.apply(this, arguments);
1815+
var _a;
1816+
return (_a = __privateGet(this, _events).bind) == null ? void 0 : _a.apply(this, arguments);
18141817
}
18151818
removeEventListener() {
1816-
return __privateGet(this, _events).removeEventListener.apply(this, arguments);
1819+
var _a;
1820+
return (_a = __privateGet(this, _events).removeEventListener) == null ? void 0 : _a.apply(this, arguments);
18171821
}
18181822
off() {
1819-
return __privateGet(this, _events).off.apply(this, arguments);
1823+
var _a;
1824+
return (_a = __privateGet(this, _events).off) == null ? void 0 : _a.apply(this, arguments);
18201825
}
18211826
unbind() {
1822-
return __privateGet(this, _events).unbind.apply(this, arguments);
1827+
var _a;
1828+
return (_a = __privateGet(this, _events).unbind) == null ? void 0 : _a.apply(this, arguments);
18231829
}
18241830
dispatchEvent() {
1825-
return __privateGet(this, _events).dispatchEvent.apply(this, arguments);
1831+
var _a;
1832+
return (_a = __privateGet(this, _events).dispatchEvent) == null ? void 0 : _a.apply(this, arguments);
18261833
}
18271834
trigger() {
1828-
return __privateGet(this, _events).trigger.apply(this, arguments);
1835+
var _a;
1836+
return (_a = __privateGet(this, _events).trigger) == null ? void 0 : _a.apply(this, arguments);
18291837
}
18301838
listen() {
1831-
return __privateGet(this, _events).listen.apply(this, arguments);
1839+
var _a;
1840+
return (_a = __privateGet(this, _events).listen) == null ? void 0 : _a.apply(this, arguments);
18321841
}
18331842
ignore() {
1834-
return __privateGet(this, _events).ignore.apply(this, arguments);
1843+
var _a;
1844+
return (_a = __privateGet(this, _events).ignore) == null ? void 0 : _a.apply(this, arguments);
18351845
}
18361846
pop() {
18371847
const popped = super.pop.apply(this, arguments);
@@ -4147,8 +4157,7 @@ var _Shape = class _Shape extends Element {
41474157
/**
41484158
* @name Two.Shape#dispose
41494159
* @function
4150-
* @description Release the element's renderer object and detach any events.
4151-
* This cleans up renderer-specific resources and unbinds all event listeners.
4160+
* @description Release the shape's bound objects by unbinding relevant events.
41524161
*/
41534162
dispose() {
41544163
super.dispose();
@@ -15769,34 +15778,44 @@ var _Two = class _Two {
1576915778
this._events._bound = v;
1577015779
}
1577115780
addEventListener() {
15772-
return this._events.addEventListener.apply(this, arguments);
15781+
var _a;
15782+
return (_a = this._events.addEventListener) == null ? void 0 : _a.apply(this, arguments);
1577315783
}
1577415784
on() {
15775-
return this._events.addEventListener.apply(this, arguments);
15785+
var _a;
15786+
return (_a = this._events.addEventListener) == null ? void 0 : _a.apply(this, arguments);
1577615787
}
1577715788
bind() {
15778-
return this._events.addEventListener.apply(this, arguments);
15789+
var _a;
15790+
return (_a = this._events.addEventListener) == null ? void 0 : _a.apply(this, arguments);
1577915791
}
1578015792
removeEventListener() {
15781-
return this._events.removeEventListener.apply(this, arguments);
15793+
var _a;
15794+
return (_a = this._events.removeEventListener) == null ? void 0 : _a.apply(this, arguments);
1578215795
}
1578315796
off() {
15784-
return this._events.removeEventListener.apply(this, arguments);
15797+
var _a;
15798+
return (_a = this._events.removeEventListener) == null ? void 0 : _a.apply(this, arguments);
1578515799
}
1578615800
unbind() {
15787-
return this._events.removeEventListener.apply(this, arguments);
15801+
var _a;
15802+
return (_a = this._events.removeEventListener) == null ? void 0 : _a.apply(this, arguments);
1578815803
}
1578915804
dispatchEvent() {
15790-
return this._events.dispatchEvent.apply(this, arguments);
15805+
var _a;
15806+
return (_a = this._events.dispatchEvent) == null ? void 0 : _a.apply(this, arguments);
1579115807
}
1579215808
trigger() {
15793-
return this._events.dispatchEvent.apply(this, arguments);
15809+
var _a;
15810+
return (_a = this._events.dispatchEvent) == null ? void 0 : _a.apply(this, arguments);
1579415811
}
1579515812
listen() {
15796-
return this._events.listen.apply(this, arguments);
15813+
var _a;
15814+
return (_a = this._events.listen) == null ? void 0 : _a.apply(this, arguments);
1579715815
}
1579815816
ignore() {
15799-
return this._events.ignore.apply(this, arguments);
15817+
var _a;
15818+
return (_a = this._events.ignore) == null ? void 0 : _a.apply(this, arguments);
1580015819
}
1580115820
/**
1580215821
* @name Two#appendTo

wiki/changelog/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ All notable changes to this project will be documented in this file. The format
1111

1212
<carbon-ads />
1313

14-
## Nightly
14+
## December 22, 2025 v0.8.23
1515

16+
<h3 class="visible">Dec 22, 2025</h3><version-link v="v0.8.23" />
17+
18+
- Made `Two.Event` private getter more relaxed
1619
- Added `Two.Shape.dispose`
1720
- Added test suite for `dispose` methods
1821

wiki/docs/effects/image-sequence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A convenient package to display still or animated images organized as a series o
3030

3131
| Argument | Description |
3232
| ---- | ----------- |
33-
| paths | A list of URLs or [Two.Texture](/docs/effects/texture/)s. |
33+
| src | A list of URLs or [Two.Texture](/docs/effects/texture/)s. |
3434
| ox | The initial `x` position of the Two.ImageSequence. |
3535
| oy | The initial `y` position of the Two.ImageSequence. |
3636
| frameRate | The frame rate at which the images should playback at. |

wiki/docs/effects/image/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A convenient package to display images scaled to fit specific dimensions. Unlike
3030

3131
| Argument | Description |
3232
| ---- | ----------- |
33-
| path | The URL path or [Two.Texture](/docs/effects/texture/) to be used as the bitmap data displayed on the image. |
33+
| src | The URL path or [Two.Texture](/docs/effects/texture/) to be used as the bitmap data displayed on the image. |
3434
| ox | The initial `x` position of the Two.Image. |
3535
| oy | The initial `y` position of the Two.Image. |
3636
| width | The width to display the image at. |

wiki/docs/effects/sprite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A convenient package to display still or animated images through a tiled image s
3030

3131
| Argument | Description |
3232
| ---- | ----------- |
33-
| path | The URL path or [Two.Texture](/docs/effects/texture/) to be used as the bitmap data displayed on the sprite. |
33+
| src | The URL path or [Two.Texture](/docs/effects/texture/) to be used as the bitmap data displayed on the sprite. |
3434
| ox | The initial `x` position of the Two.Sprite. |
3535
| oy | The initial `y` position of the Two.Sprite. |
3636
| cols | The number of columns the sprite contains. |

wiki/docs/path/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,8 +1878,8 @@ The sum of distances between all [Two.Path.vertices](/docs/path/#vertices).
18781878

18791879
<div class="meta">
18801880

1881-
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1613">
1882-
path.js:1613
1881+
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1621">
1882+
path.js:1621
18831883
</a>
18841884

18851885
</div>
@@ -1925,8 +1925,8 @@ The shape whose alpha property becomes a clipping area for the path.
19251925

19261926
<div class="meta">
19271927

1928-
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1722">
1929-
path.js:1722
1928+
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1730">
1929+
path.js:1730
19301930
</a>
19311931

19321932
</div>
@@ -1982,8 +1982,8 @@ Tells Two.js renderer if this object represents a mask for another object (or no
19821982

19831983
<div class="meta">
19841984

1985-
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1743">
1986-
path.js:1743
1985+
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1751">
1986+
path.js:1751
19871987
</a>
19881988

19891989
</div>
@@ -2035,8 +2035,8 @@ When `strokeAttenuation` is `false`, the stroke width is automatically adjusted
20352035

20362036
<div class="meta">
20372037

2038-
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1771">
2039-
path.js:1771
2038+
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/path.js#L1779">
2039+
path.js:1779
20402040
</a>
20412041

20422042
</div>

wiki/docs/shape/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,3 +917,48 @@ Works in conjunction with [Two.Shape.fromObject](/docs/shape/#fromobject)
917917
</div>
918918

919919

920+
921+
<div class="instance function ">
922+
923+
## dispose
924+
925+
<h2 class="longname" aria-hidden="true"><a href="#dispose"><span class="prefix">Two.Shape.</span><span class="shortname">dispose</span></a></h2>
926+
927+
928+
929+
930+
931+
932+
933+
934+
935+
936+
937+
938+
939+
940+
941+
<div class="description">
942+
943+
Release the shape's bound objects by unbinding relevant events.
944+
945+
</div>
946+
947+
948+
949+
950+
951+
<div class="meta">
952+
953+
<a class="lineno" target="_blank" rel="noopener noreferrer" href="https://github.com/jonobr1/two.js/blob/main/src/shape.js#L354">
954+
shape.js:354
955+
</a>
956+
957+
</div>
958+
959+
960+
961+
962+
</div>
963+
964+

0 commit comments

Comments
 (0)