Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Clearing animation timeout on unmount #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lib/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ var _reactAddonsTransitionGroup = require('react-addons-transition-group');

var _reactAddonsTransitionGroup2 = _interopRequireDefault(_reactAddonsTransitionGroup);

var _createReactClass = require('create-react-class');

var _createReactClass2 = _interopRequireDefault(_createReactClass);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* eslint no-unused-vars:0 */
/*global window, document, getComputedStyle*/

var Clones = _react2.default.createClass({
var Clones = (0, _createReactClass2.default)({
displayName: 'ShuffleClones',

_childrenWithPositions: function _childrenWithPositions() {
Expand Down Expand Up @@ -67,7 +75,7 @@ var Clones = _react2.default.createClass({
}
});

var Clone = _react2.default.createClass({
var Clone = (0, _createReactClass2.default)({
mixins: [_reactTweenState2.default.Mixin],
displayName: 'ShuffleClone',
getInitialState: function getInitialState() {
Expand Down Expand Up @@ -141,15 +149,15 @@ var Clone = _react2.default.createClass({
}
});

var Shuffle = _react2.default.createClass({
var Shuffle = (0, _createReactClass2.default)({

displayName: 'Shuffle',

propTypes: {
duration: _react2.default.PropTypes.number,
scale: _react2.default.PropTypes.bool,
fade: _react2.default.PropTypes.bool,
initial: _react2.default.PropTypes.bool
duration: _propTypes2.default.number,
scale: _propTypes2.default.bool,
fade: _propTypes2.default.bool,
initial: _propTypes2.default.bool
},

getDefaultProps: function getDefaultProps() {
Expand All @@ -171,6 +179,7 @@ var Shuffle = _react2.default.createClass({
window.addEventListener('resize', this._renderClonesInitially);
},
componentWillUnmount: function componentWillUnmount() {
clearTimeout(this._timeout);
_reactDom2.default.unmountComponentAtNode(this._portalNode);
_reactDom2.default.findDOMNode(this.refs.container).removeChild(this._portalNode);
window.removeEventListener('resize', this._renderClonesInitially);
Expand All @@ -197,7 +206,8 @@ var Shuffle = _react2.default.createClass({
_reactDom2.default.findDOMNode(this.refs.container).appendChild(this._portalNode);
},
_addTransitionEndEvent: function _addTransitionEndEvent() {
setTimeout(this._finishAnimation, this.props.duration);
clearTimeout(this._timeout);
this._timeout = setTimeout(this._finishAnimation, this.props.duration);
},
_startAnimation: function _startAnimation(nextProps) {
var _this3 = this;
Expand Down Expand Up @@ -280,6 +290,7 @@ var Shuffle = _react2.default.createClass({
duration = _props.duration,
props = _objectWithoutProperties(_props, ['initial', 'fade', 'duration']);

props.scale = !!this.props.scale + '';
var showContainer = initial ? 0 : 1;
if (this.state.ready) {
showContainer = 0;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
"main": "index.js",
"dependencies": {
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"create-react-class": "^15.5.3",
"object-assign": "^4.0.1",
"prop-types": "^15.5.10",
"react-addons-transition-group": "^15.0.0 || ^0.14.0",

"react-tween-state": "^0.1.5"
},
"peerDependencies": {
Expand Down
21 changes: 13 additions & 8 deletions src/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import ReactDom from 'react-dom';
import assign from 'object-assign';
import tweenState from 'react-tween-state';
import ReactTransitionGroup from 'react-addons-transition-group';
import createReactClass from 'create-react-class'
import PropTypes from 'prop-types';

const Clones = React.createClass({
const Clones = createReactClass({
displayName: 'ShuffleClones',

_childrenWithPositions() {
Expand Down Expand Up @@ -40,7 +42,7 @@ const Clones = React.createClass({
}
});

const Clone = React.createClass({
const Clone = createReactClass({
mixins: [tweenState.Mixin],
displayName: 'ShuffleClone',
getInitialState() {
Expand Down Expand Up @@ -116,15 +118,15 @@ const Clone = React.createClass({
}
})

const Shuffle = React.createClass({
const Shuffle = createReactClass({

displayName: 'Shuffle',

propTypes: {
duration: React.PropTypes.number,
scale: React.PropTypes.bool,
fade: React.PropTypes.bool,
initial: React.PropTypes.bool
duration: PropTypes.number,
scale: PropTypes.bool,
fade: PropTypes.bool,
initial: PropTypes.bool
},

getDefaultProps() {
Expand All @@ -149,6 +151,7 @@ const Shuffle = React.createClass({
},

componentWillUnmount() {
clearTimeout(this._timeout);
ReactDom.unmountComponentAtNode(this._portalNode);
ReactDom.findDOMNode(this.refs.container).removeChild(this._portalNode);
window.removeEventListener('resize', this._renderClonesInitially);
Expand Down Expand Up @@ -177,7 +180,8 @@ const Shuffle = React.createClass({
},

_addTransitionEndEvent() {
setTimeout(this._finishAnimation, this.props.duration);
clearTimeout(this._timeout);
this._timeout = setTimeout(this._finishAnimation, this.props.duration);
},

_startAnimation(nextProps) {
Expand Down Expand Up @@ -259,6 +263,7 @@ const Shuffle = React.createClass({

render() {
let { initial, fade, duration, ...props } = this.props;
props.scale = (!!this.props.scale)+'';
var showContainer = initial ? 0 : 1;
if (this.state.ready) {
showContainer = 0;
Expand Down