diff --git a/CHANGELOG.md b/CHANGELOG.md index bdbf814..7132c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # React Typist Changelog + +### v1.0.3 (10/01/16) + +- Fixes + + Component no longer sets `isDone` state if unmounted + + ### v1.0.1 (10/01/16) - Fixes diff --git a/dist/Typist.js b/dist/Typist.js index 18194c5..5eb661d 100644 --- a/dist/Typist.js +++ b/dist/Typist.js @@ -91,6 +91,9 @@ module.exports = }; _this.onTypingDone = function () { + if (!_this.mounted) { + return; + } _this.setState({ isDone: true }); _this.props.onTypingDone(); }; diff --git a/dist/standalone/Typist.js b/dist/standalone/Typist.js index 1cbaad4..2adf186 100644 --- a/dist/standalone/Typist.js +++ b/dist/standalone/Typist.js @@ -100,6 +100,9 @@ return /******/ (function(modules) { // webpackBootstrap }; _this.onTypingDone = function () { + if (!_this.mounted) { + return; + } _this.setState({ isDone: true }); _this.props.onTypingDone(); }; diff --git a/dist/standalone/Typist.min.js b/dist/standalone/Typist.min.js index eff92cf..5f62736 100644 --- a/dist/standalone/Typist.min.js +++ b/dist/standalone/Typist.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Typist=t(require("react")):e.Typist=t(e.react)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t["default"]=e,t}function o(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:i,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a;return h.gaussianRnd(e,t)}})},n.mounted=!1,n.linesToType=[],e.children&&(n.linesToType=h.extractText(e.children)),n}return u(t,e),l(t,[{key:"componentDidMount",value:function(){this.mounted=!0;var e=this.props,t=e.children,n=e.startDelay;t?n>0&&"undefined"!=typeof window?setTimeout(this.typeAllLines.bind(this),n):this.typeAllLines():this.onTypingDone()}},{key:"shouldComponentUpdate",value:function(e,t){for(var n=0;n0)return!0}return this.state.isDone!==t.isDone}},{key:"componentWillUnmount",value:function(){this.mounted=!1}},{key:"typeAllLines",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.linesToType;return h.eachPromise(t,function(t,n){return e.mounted?new Promise(function(r){e.setState({text:e.state.text.concat([""])},function(){e.typeLine(t,n).then(r)})}):Promise.resolve()}).then(function(){return e.onTypingDone()})}},{key:"typeLine",value:function(e,t){var n=this;return h.eachPromise(e,function(r,o){return n.mounted?new Promise(function(i){var a=n.state.text.slice();a[t]+=r,n.setState({text:a},function(){var a=n.delayGenerator(e,t,r,o);setTimeout(i,a)})}):Promise.resolve()})}},{key:"render",value:function(){var e=this.props,t=e.className,n=e.cursor,r=this.state.isDone,o=h.extractTreeWithText(this.props.children,this.state.text);return p["default"].createElement("div",{className:"Typist "+t},o,p["default"].createElement(y["default"],s({isDone:r},n)))}}]),t}(c.Component);v.propTypes={children:c.PropTypes.node,className:c.PropTypes.string,avgTypingDelay:c.PropTypes.number,stdTypingDelay:c.PropTypes.number,startDelay:c.PropTypes.number,cursor:c.PropTypes.object,onTypingDone:c.PropTypes.func,delayGenerator:c.PropTypes.func},v.defaultProps={className:"",avgTypingDelay:70,stdTypingDelay:25,startDelay:0,cursor:{},onTypingDone:function(){},delayGenerator:h.gaussianRnd},t["default"]=v},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n0;){var r=t.pop();if(y["default"].isValidElement(r))y["default"].Children.forEach(r.props.children,function(e){t.push(e)});else if(Array.isArray(r)){var o=!0,i=!1,a=void 0;try{for(var u,s=r[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var l=u.value;t.push(l)}}catch(c){i=!0,a=c}finally{try{!o&&s["return"]&&s["return"]()}finally{if(i)throw a}}}else n.unshift(r)}return n}function l(){var e=0;return function(t){var n=t.type,r=u(t.props,["children"]);return r.key="Typist-el-"+e++,y["default"].createElement.bind(null,n,r)}}function c(){for(var e=arguments.length,t=Array(e),n=0;n=t.length)return[null,n];var i=n,u=function(e){var n=a(e,t,i),r=p(n,2),o=r[0],u=r[1];return i=u,o};if(y["default"].isValidElement(e)){var s=r(e),l=y["default"].Children.map(e.props.children,u)||[];return[s.apply(void 0,o(l)),i]}if(Array.isArray(e)){var c=e.map(u);return[c,i]}return[t[i],i+1]};return i.apply(void 0,t.concat([0]))[0]}}Object.defineProperty(t,"__esModule",{value:!0}),t.sleep=void 0;var p=function(){function e(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){o=!0,i=s}finally{try{!r&&u["return"]&&u["return"]()}finally{if(o)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.gaussianRnd=i,t.eachPromise=a,t.exclude=u,t.extractText=s,t.elementFactoryMaker=l,t.extractTreeWithText=c;var f=n(1),y=r(f);t.sleep=function(e){return new Promise(function(t){return setTimeout(t,e)})}}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Typist=t(require("react")):e.Typist=t(e.react)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t["default"]=e,t}function o(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:i,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a;return h.gaussianRnd(e,t)}})},n.mounted=!1,n.linesToType=[],e.children&&(n.linesToType=h.extractText(e.children)),n}return u(t,e),l(t,[{key:"componentDidMount",value:function(){this.mounted=!0;var e=this.props,t=e.children,n=e.startDelay;t?n>0&&"undefined"!=typeof window?setTimeout(this.typeAllLines.bind(this),n):this.typeAllLines():this.onTypingDone()}},{key:"shouldComponentUpdate",value:function(e,t){for(var n=0;n0)return!0}return this.state.isDone!==t.isDone}},{key:"componentWillUnmount",value:function(){this.mounted=!1}},{key:"typeAllLines",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.linesToType;return h.eachPromise(t,function(t,n){return e.mounted?new Promise(function(r){e.setState({text:e.state.text.concat([""])},function(){e.typeLine(t,n).then(r)})}):Promise.resolve()}).then(function(){return e.onTypingDone()})}},{key:"typeLine",value:function(e,t){var n=this;return h.eachPromise(e,function(r,o){return n.mounted?new Promise(function(i){var a=n.state.text.slice();a[t]+=r,n.setState({text:a},function(){var a=n.delayGenerator(e,t,r,o);setTimeout(i,a)})}):Promise.resolve()})}},{key:"render",value:function(){var e=this.props,t=e.className,n=e.cursor,r=this.state.isDone,o=h.extractTreeWithText(this.props.children,this.state.text);return p["default"].createElement("div",{className:"Typist "+t},o,p["default"].createElement(y["default"],s({isDone:r},n)))}}]),t}(c.Component);v.propTypes={children:c.PropTypes.node,className:c.PropTypes.string,avgTypingDelay:c.PropTypes.number,stdTypingDelay:c.PropTypes.number,startDelay:c.PropTypes.number,cursor:c.PropTypes.object,onTypingDone:c.PropTypes.func,delayGenerator:c.PropTypes.func},v.defaultProps={className:"",avgTypingDelay:70,stdTypingDelay:25,startDelay:0,cursor:{},onTypingDone:function(){},delayGenerator:h.gaussianRnd},t["default"]=v},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n0;){var r=t.pop();if(y["default"].isValidElement(r))y["default"].Children.forEach(r.props.children,function(e){t.push(e)});else if(Array.isArray(r)){var o=!0,i=!1,a=void 0;try{for(var u,s=r[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var l=u.value;t.push(l)}}catch(c){i=!0,a=c}finally{try{!o&&s["return"]&&s["return"]()}finally{if(i)throw a}}}else n.unshift(r)}return n}function l(){var e=0;return function(t){var n=t.type,r=u(t.props,["children"]);return r.key="Typist-el-"+e++,y["default"].createElement.bind(null,n,r)}}function c(){for(var e=arguments.length,t=Array(e),n=0;n=t.length)return[null,n];var i=n,u=function(e){var n=a(e,t,i),r=p(n,2),o=r[0],u=r[1];return i=u,o};if(y["default"].isValidElement(e)){var s=r(e),l=y["default"].Children.map(e.props.children,u)||[];return[s.apply(void 0,o(l)),i]}if(Array.isArray(e)){var c=e.map(u);return[c,i]}return[t[i],i+1]};return i.apply(void 0,t.concat([0]))[0]}}Object.defineProperty(t,"__esModule",{value:!0}),t.sleep=void 0;var p=function(){function e(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){o=!0,i=s}finally{try{!r&&u["return"]&&u["return"]()}finally{if(o)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.gaussianRnd=i,t.eachPromise=a,t.exclude=u,t.extractText=s,t.elementFactoryMaker=l,t.extractTreeWithText=c;var f=n(1),y=r(f);t.sleep=function(e){return new Promise(function(t){return setTimeout(t,e)})}}])}); \ No newline at end of file diff --git a/package.json b/package.json index 41e3c8b..0a4aeeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-typist", - "version": "1.0.2", + "version": "1.0.3", "description": "Typing animations with React", "main": "dist/Typist.js", "scripts": {