Skip to content

Commit 4502275

Browse files
committed
version bump and fixed memory leak
1 parent 5d149b6 commit 4502275

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-rotating-text",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A simple react component to display an array of words/sentences with a typewriter effect.",
55
"main": "lib/ReactRotatingText.js",
66
"author": "Adrian Li",

src/ReactRotatingText.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class ReactRotatingText extends React.Component {
2323
// save the timeouts so we can stop on unmount
2424
const timeout = setTimeout(loopingFunc, pause);
2525
this.timeouts.push(timeout);
26+
27+
// prevent memory leak
28+
const maxTimeouts = 100;
29+
if (this.timeouts.length > maxTimeouts) {
30+
clearTimeout(this.timeouts[0]);
31+
this.timeouts.shift();
32+
}
2633
}
2734

2835
_type(text, callback) {
@@ -72,7 +79,7 @@ class ReactRotatingText extends React.Component {
7279
};
7380

7481
type.bind(this)(items[index], () => {
75-
this._loop(erase.bind(this,nextWord), pause);
82+
this._loop(erase.bind(this, nextWord), pause);
7683
});
7784
};
7885

0 commit comments

Comments
 (0)