├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── TimerMixin.js ├── __tests__ └── TimerMixin-test.js └── package.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "jasmine": true, 4 | }, 5 | 6 | // Map from global var to bool specifying if it can be redefined 7 | "globals": { 8 | "__DEV__": true, 9 | "__dirname": false, 10 | "__fbBatchedBridgeConfig": false, 11 | "cancelAnimationFrame": false, 12 | "clearImmediate": true, 13 | "clearInterval": false, 14 | "clearTimeout": false, 15 | "console": false, 16 | "document": false, 17 | "escape": false, 18 | "exports": false, 19 | "global": false, 20 | "jest": false, 21 | "Map": true, 22 | "module": false, 23 | "process": false, 24 | "Promise": true, 25 | "requestAnimationFrame": true, 26 | "require": false, 27 | "Set": true, 28 | "setImmediate": true, 29 | "setInterval": false, 30 | "setTimeout": false, 31 | "window": false, 32 | "XMLHttpRequest": false, 33 | "pit": false 34 | }, 35 | 36 | "rules": { 37 | "no-cond-assign": 1, // disallow assignment in conditional expressions 38 | "no-console": 0, // disallow use of console (off by default in the node environment) 39 | "no-constant-condition": 1, // disallow use of constant expressions in conditions 40 | "no-comma-dangle": 0, // disallow trailing commas in object literals 41 | "no-control-regex": 1, // disallow control characters in regular expressions 42 | "no-debugger": 1, // disallow use of debugger 43 | "no-dupe-keys": 1, // disallow duplicate keys when creating object literals 44 | "no-empty": 0, // disallow empty statements 45 | "no-empty-class": 1, // disallow the use of empty character classes in regular expressions 46 | "no-ex-assign": 1, // disallow assigning to the exception in a catch block 47 | "no-extra-boolean-cast": 1, // disallow double-negation boolean casts in a boolean context 48 | "no-extra-parens": 0, // disallow unnecessary parentheses (off by default) 49 | "no-extra-semi": 1, // disallow unnecessary semicolons 50 | "no-func-assign": 1, // disallow overwriting functions written as function declarations 51 | "no-inner-declarations": 0, // disallow function or variable declarations in nested blocks 52 | "no-invalid-regexp": 1, // disallow invalid regular expression strings in the RegExp constructor 53 | "no-negated-in-lhs": 1, // disallow negation of the left operand of an in expression 54 | "no-obj-calls": 1, // disallow the use of object properties of the global object (Math and JSON) as functions 55 | "no-regex-spaces": 1, // disallow multiple spaces in a regular expression literal 56 | "no-reserved-keys": 0, // disallow reserved words being used as object literal keys (off by default) 57 | "no-sparse-arrays": 1, // disallow sparse arrays 58 | "no-unreachable": 1, // disallow unreachable statements after a return, throw, continue, or break statement 59 | "use-isnan": 1, // disallow comparisons with the value NaN 60 | "valid-jsdoc": 0, // Ensure JSDoc comments are valid (off by default) 61 | "valid-typeof": 1, // Ensure that the results of typeof are compared against a valid string 62 | 63 | // Best Practices 64 | // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns. 65 | 66 | "block-scoped-var": 0, // treat var statements as if they were block scoped (off by default) 67 | "complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default) 68 | "consistent-return": 0, // require return statements to either always or never specify values 69 | "curly": 1, // specify curly brace conventions for all control statements 70 | "default-case": 0, // require default case in switch statements (off by default) 71 | "dot-notation": 1, // encourages use of dot notation whenever possible 72 | "eqeqeq": 1, // require the use of === and !== 73 | "guard-for-in": 0, // make sure for-in loops have an if statement (off by default) 74 | "no-alert": 1, // disallow the use of alert, confirm, and prompt 75 | "no-caller": 1, // disallow use of arguments.caller or arguments.callee 76 | "no-div-regex": 1, // disallow division operators explicitly at beginning of regular expression (off by default) 77 | "no-else-return": 0, // disallow else after a return in an if (off by default) 78 | "no-empty-label": 1, // disallow use of labels for anything other then loops and switches 79 | "no-eq-null": 0, // disallow comparisons to null without a type-checking operator (off by default) 80 | "no-eval": 1, // disallow use of eval() 81 | "no-extend-native": 1, // disallow adding to native types 82 | "no-extra-bind": 1, // disallow unnecessary function binding 83 | "no-fallthrough": 1, // disallow fallthrough of case statements 84 | "no-floating-decimal": 1, // disallow the use of leading or trailing decimal points in numeric literals (off by default) 85 | "no-implied-eval": 1, // disallow use of eval()-like methods 86 | "no-labels": 1, // disallow use of labeled statements 87 | "no-iterator": 1, // disallow usage of __iterator__ property 88 | "no-lone-blocks": 1, // disallow unnecessary nested blocks 89 | "no-loop-func": 0, // disallow creation of functions within loops 90 | "no-multi-str": 0, // disallow use of multiline strings 91 | "no-native-reassign": 0, // disallow reassignments of native objects 92 | "no-new": 1, // disallow use of new operator when not part of the assignment or comparison 93 | "no-new-func": 1, // disallow use of new operator for Function object 94 | "no-new-wrappers": 1, // disallows creating new instances of String,Number, and Boolean 95 | "no-octal": 1, // disallow use of octal literals 96 | "no-octal-escape": 1, // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251"; 97 | "no-proto": 1, // disallow usage of __proto__ property 98 | "no-redeclare": 0, // disallow declaring the same variable more then once 99 | "no-return-assign": 1, // disallow use of assignment in return statement 100 | "no-script-url": 1, // disallow use of javascript: urls. 101 | "no-self-compare": 1, // disallow comparisons where both sides are exactly the same (off by default) 102 | "no-sequences": 1, // disallow use of comma operator 103 | "no-unused-expressions": 0, // disallow usage of expressions in statement position 104 | "no-void": 1, // disallow use of void operator (off by default) 105 | "no-warning-comments": 0, // disallow usage of configurable warning terms in comments": 1, // e.g. TODO or FIXME (off by default) 106 | "no-with": 1, // disallow use of the with statement 107 | "radix": 1, // require use of the second argument for parseInt() (off by default) 108 | "vars-on-top": 0, // requires to declare all vars on top of their containing scope (off by default) 109 | "wrap-iife": 0, // require immediate function invocation to be wrapped in parentheses (off by default) 110 | "yoda": 1, // require or disallow Yoda conditions 111 | 112 | // Strict Mode 113 | // These rules relate to using strict mode. 114 | 115 | "global-strict": [2, "always"], // require or disallow the "use strict" pragma in the global scope (off by default in the node environment) 116 | "no-extra-strict": 1, // disallow unnecessary use of "use strict"; when already in strict mode 117 | "strict": 0, // require that all functions are run in strict mode 118 | 119 | // Variables 120 | // These rules have to do with variable declarations. 121 | 122 | "no-catch-shadow": 1, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment) 123 | "no-delete-var": 1, // disallow deletion of variables 124 | "no-label-var": 1, // disallow labels that share a name with a variable 125 | "no-shadow": 1, // disallow declaration of variables already declared in the outer scope 126 | "no-shadow-restricted-names": 1, // disallow shadowing of names such as arguments 127 | "no-undef": 2, // disallow use of undeclared variables unless mentioned in a /*global */ block 128 | "no-undefined": 0, // disallow use of undefined variable (off by default) 129 | "no-undef-init": 1, // disallow use of undefined when initializing variables 130 | "no-unused-vars": [1, {"vars": "all", "args": "none"}], // disallow declaration of variables that are not used in the code 131 | "no-use-before-define": 0, // disallow use of variables before they are defined 132 | 133 | // Node.js 134 | // These rules are specific to JavaScript running on Node.js. 135 | 136 | "handle-callback-err": 1, // enforces error handling in callbacks (off by default) (on by default in the node environment) 137 | "no-mixed-requires": 1, // disallow mixing regular variable and require declarations (off by default) (on by default in the node environment) 138 | "no-new-require": 1, // disallow use of new operator with the require function (off by default) (on by default in the node environment) 139 | "no-path-concat": 1, // disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment) 140 | "no-process-exit": 0, // disallow process.exit() (on by default in the node environment) 141 | "no-restricted-modules": 1, // restrict usage of specified node modules (off by default) 142 | "no-sync": 0, // disallow use of synchronous methods (off by default) 143 | 144 | // Stylistic Issues 145 | // These rules are purely matters of style and are quite subjective. 146 | 147 | "key-spacing": 0, 148 | "comma-spacing": 0, 149 | "no-multi-spaces": 0, 150 | "brace-style": 0, // enforce one true brace style (off by default) 151 | "camelcase": 0, // require camel case names 152 | "consistent-this": [1, "self"], // enforces consistent naming when capturing the current execution context (off by default) 153 | "eol-last": 1, // enforce newline at the end of file, with no multiple empty lines 154 | "func-names": 0, // require function expressions to have a name (off by default) 155 | "func-style": 0, // enforces use of function declarations or expressions (off by default) 156 | "new-cap": 0, // require a capital letter for constructors 157 | "new-parens": 1, // disallow the omission of parentheses when invoking a constructor with no arguments 158 | "no-nested-ternary": 0, // disallow nested ternary expressions (off by default) 159 | "no-array-constructor": 1, // disallow use of the Array constructor 160 | "no-lonely-if": 0, // disallow if as the only statement in an else block (off by default) 161 | "no-new-object": 1, // disallow use of the Object constructor 162 | "no-spaced-func": 1, // disallow space between function identifier and application 163 | "no-space-before-semi": 1, // disallow space before semicolon 164 | "no-ternary": 0, // disallow the use of ternary operators (off by default) 165 | "no-trailing-spaces": 1, // disallow trailing whitespace at the end of lines 166 | "no-underscore-dangle": 0, // disallow dangling underscores in identifiers 167 | "no-wrap-func": 1, // disallow wrapping of non-IIFE statements in parens 168 | "no-mixed-spaces-and-tabs": 1, // disallow mixed spaces and tabs for indentation 169 | "quotes": [1, "single"], // specify whether double or single quotes should be used 170 | "quote-props": 0, // require quotes around object literal property names (off by default) 171 | "semi": 1, // require or disallow use of semicolons instead of ASI 172 | "sort-vars": 0, // sort variables within the same declaration block (off by default) 173 | "space-after-keywords": 1, // require a space after certain keywords (off by default) 174 | "space-in-brackets": 0, // require or disallow spaces inside brackets (off by default) 175 | "space-in-parens": 0, // require or disallow spaces inside parentheses (off by default) 176 | "space-infix-ops": 1, // require spaces around operators 177 | "space-return-throw-case": 1, // require a space after return, throw, and case 178 | "space-unary-word-ops": 1, // require a space around word operators such as typeof (off by default) 179 | "max-nested-callbacks": 0, // specify the maximum depth callbacks can be nested (off by default) 180 | "one-var": 0, // allow just one var statement per function (off by default) 181 | "wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default) 182 | 183 | // Legacy 184 | // The following rules are included for compatibility with JSHint and JSLint. While the names of the rules may not match up with the JSHint/JSLint counterpart, the functionality is the same. 185 | 186 | "max-depth": 0, // specify the maximum depth that blocks can be nested (off by default) 187 | "max-len": 0, // specify the maximum length of a line in your program (off by default) 188 | "max-params": 0, // limits the number of parameters that can be used in the function declaration. (off by default) 189 | "max-statements": 0, // specify the maximum number of statement allowed in a function (off by default) 190 | "no-bitwise": 1, // disallow use of bitwise operators (off by default) 191 | "no-plusplus": 0 // disallow use of unary operators, ++ and -- (off by default) 192 | } 193 | } 194 | 195 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - '0.10' 5 | sudo: false 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to react-timer-mixin 2 | We want to make contributing to this project as easy and transparent as 3 | possible. 4 | 5 | ## Our Development Process 6 | The majority of development on react-timer-mixin will occur through GitHub. Accordingly, 7 | the process for contributing will follow standard GitHub protocol. 8 | 9 | ## Pull Requests 10 | We actively welcome your pull requests. 11 | 1. Fork the repo and create your branch from `master`. 12 | 2. If you've added code that should be tested, add tests 13 | 3. If you've changed APIs, update the documentation. 14 | 4. Ensure the test suite passes. 15 | 5. Make sure your code lints and typechecks. 16 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 17 | 18 | ## Contributor License Agreement ("CLA") 19 | In order to accept your pull request, we need you to submit a CLA. You only need 20 | to do this once to work on any of Facebook's open source projects. 21 | 22 | Complete your CLA here: 23 | 24 | ## Issues 25 | We use GitHub issues to track public bugs. Please ensure your description is 26 | clear and has sufficient instructions to be able to reproduce the issue. 27 | 28 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 29 | disclosure of security bugs. In those cases, please go through the process 30 | outlined on that page and do not file a public issue. 31 | 32 | ## Coding Style 33 | * Use semicolons; 34 | * Commas last, 35 | * 2 spaces for indentation (no tabs) 36 | * Prefer `'` over `"` 37 | * `"use strict";` 38 | * 80 character line length 39 | * "Attractive" 40 | 41 | ## License 42 | By contributing to react-timer-mixin, you agree that your contributions will be licensed 43 | under its MIT license. 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Facebook, Inc. and its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-timer-mixin 2 | 3 | Using bare setTimeout, setInterval, setImmediate and requestAnimationFrame calls 4 | is very dangerous because if you forget to cancel the request before the 5 | component is unmounted, you risk the callback throwing an exception. 6 | 7 | If you include TimerMixin, then you can replace your calls to 8 | `setTimeout(fn, 500)` with `this.setTimeout(fn, 500)` (just prepend `this.`) and 9 | everything will be properly cleaned up for you. 10 | 11 | ## Installation 12 | 13 | Install the module directly from npm: 14 | 15 | ``` 16 | npm install react-timer-mixin 17 | ``` 18 | 19 | ## Example 20 | 21 | ```js 22 | var React = require('react'); 23 | var TimerMixin = require('react-timer-mixin'); 24 | 25 | var Component = React.createClass({ 26 | mixins: [TimerMixin], 27 | componentDidMount() { 28 | this.setTimeout( 29 | () => { console.log('I do not leak!'); }, 30 | 500 31 | ); 32 | } 33 | }); 34 | ``` 35 | 36 | -------------------------------------------------------------------------------- /TimerMixin.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | */ 8 | 'use strict'; 9 | 10 | var GLOBAL = typeof window === 'undefined' ? global : window; 11 | 12 | var setter = function(_setter, _clearer, array) { 13 | return function(callback, delta) { 14 | var id = _setter(function() { 15 | _clearer.call(this, id); 16 | callback.apply(this, arguments); 17 | }.bind(this), delta); 18 | 19 | if (!this[array]) { 20 | this[array] = [id]; 21 | } else { 22 | this[array].push(id); 23 | } 24 | return id; 25 | }; 26 | }; 27 | 28 | var clearer = function(_clearer, array) { 29 | return function(id) { 30 | if (this[array]) { 31 | var index = this[array].indexOf(id); 32 | if (index !== -1) { 33 | this[array].splice(index, 1); 34 | } 35 | } 36 | _clearer(id); 37 | }; 38 | }; 39 | 40 | var _timeouts = 'TimerMixin_timeouts'; 41 | var _clearTimeout = clearer(GLOBAL.clearTimeout, _timeouts); 42 | var _setTimeout = setter(GLOBAL.setTimeout, _clearTimeout, _timeouts); 43 | 44 | var _intervals = 'TimerMixin_intervals'; 45 | var _clearInterval = clearer(GLOBAL.clearInterval, _intervals); 46 | var _setInterval = setter(GLOBAL.setInterval, function() {/* noop */}, _intervals); 47 | 48 | var _immediates = 'TimerMixin_immediates'; 49 | var _clearImmediate = clearer(GLOBAL.clearImmediate, _immediates); 50 | var _setImmediate = setter(GLOBAL.setImmediate, _clearImmediate, _immediates); 51 | 52 | var _rafs = 'TimerMixin_rafs'; 53 | var _cancelAnimationFrame = clearer(GLOBAL.cancelAnimationFrame, _rafs); 54 | var _requestAnimationFrame = setter(GLOBAL.requestAnimationFrame, _cancelAnimationFrame, _rafs); 55 | 56 | var TimerMixin = { 57 | componentWillUnmount: function() { 58 | this[_timeouts] && this[_timeouts].forEach(function(id) { 59 | GLOBAL.clearTimeout(id); 60 | }); 61 | this[_timeouts] = null; 62 | this[_intervals] && this[_intervals].forEach(function(id) { 63 | GLOBAL.clearInterval(id); 64 | }); 65 | this[_intervals] = null; 66 | this[_immediates] && this[_immediates].forEach(function(id) { 67 | GLOBAL.clearImmediate(id); 68 | }); 69 | this[_immediates] = null; 70 | this[_rafs] && this[_rafs].forEach(function(id) { 71 | GLOBAL.cancelAnimationFrame(id); 72 | }); 73 | this[_rafs] = null; 74 | }, 75 | 76 | setTimeout: _setTimeout, 77 | clearTimeout: _clearTimeout, 78 | 79 | setInterval: _setInterval, 80 | clearInterval: _clearInterval, 81 | 82 | setImmediate: _setImmediate, 83 | clearImmediate: _clearImmediate, 84 | 85 | requestAnimationFrame: _requestAnimationFrame, 86 | cancelAnimationFrame: _cancelAnimationFrame, 87 | }; 88 | 89 | module.exports = TimerMixin; 90 | -------------------------------------------------------------------------------- /__tests__/TimerMixin-test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | */ 8 | 'use strict'; 9 | 10 | global.setImmediate = jest.genMockFunction(); 11 | global.clearImmediate = jest.genMockFunction(); 12 | global.requestAnimationFrame = jest.genMockFunction(); 13 | global.cancelAnimationFrame = jest.genMockFunction(); 14 | 15 | jest.dontMock('../TimerMixin'); 16 | var TimerMixin = require('../TimerMixin'); 17 | 18 | describe('TimerMixin', function() { 19 | var component; 20 | beforeEach(function() { 21 | component = Object.create(TimerMixin); 22 | // Simulate React auto-binding 23 | [ 24 | 'setTimeout', 'clearTimeout', 25 | 'setInterval', 'clearInterval', 26 | 'setImmediate', 'clearImmediate', 27 | 'requestAnimationFrame', 'cancelAnimationFrame' 28 | ].forEach(function(key) { 29 | component[key] = component[key].bind(component); 30 | }); 31 | }); 32 | 33 | [ 34 | {setter: 'setTimeout', clearer: 'clearTimeout', array: 'TimerMixin_timeouts'}, 35 | {setter: 'setInterval', clearer: 'clearInterval', array: 'TimerMixin_intervals'}, 36 | {setter: 'setImmediate', clearer: 'clearImmediate', array: 'TimerMixin_immediates'}, 37 | {setter: 'requestAnimationFrame', clearer: 'cancelAnimationFrame', array: 'TimerMixin_rafs'}, 38 | ].forEach(function(type) { 39 | it('should apply basic ' + type.setter + ' correctly', function() { 40 | expect(component[type.array]).toEqual(undefined); 41 | 42 | global[type.setter].mockClear(); 43 | global[type.setter].mockReturnValue(1); 44 | global[type.clearer].mockClear(); 45 | var cb = jest.genMockFunction(); 46 | var id = component[type.setter](cb, 10); 47 | 48 | expect(global[type.setter]).toBeCalledWith(cb, 10); 49 | expect(global[type.clearer]).not.toBeCalled(); 50 | expect(component[type.array]).toEqual([id]); 51 | 52 | component.componentWillUnmount(); 53 | 54 | expect(global[type.clearer]).toBeCalledWith(id); 55 | expect(component[type.array]).toEqual(null); 56 | }); 57 | 58 | it('should apply ' + type.clearer + ' correctly', function() { 59 | var id = 1; 60 | global[type.setter].mockClear(); 61 | global[type.setter].mockImpl(function() { return id++; }); 62 | global[type.clearer].mockClear(); 63 | var cb = jest.genMockFunction(); 64 | 65 | var id1 = component[type.setter](cb, 10); 66 | var id2 = component[type.setter](cb, 10); 67 | var id3 = component[type.setter](cb, 10); 68 | component[type.clearer](id2); 69 | expect(global[type.clearer]).toBeCalledWith(id2); 70 | var id4 = component[type.setter](cb, 10); 71 | component[type.clearer](id1); 72 | expect(global[type.clearer]).toBeCalledWith(id1); 73 | var id5 = component[type.setter](cb, 10); 74 | component[type.clearer](id5); 75 | expect(global[type.clearer]).toBeCalledWith(id5); 76 | component[type.clearer](id3); 77 | expect(global[type.clearer]).toBeCalledWith(id3); 78 | 79 | expect(component[type.array]).toEqual([id4]); 80 | component.componentWillUnmount(); 81 | expect(global[type.clearer]).toBeCalledWith(id4); 82 | expect(component[type.array]).toEqual(null); 83 | }); 84 | 85 | it('should remove bookeeping when callback is called for ' + type.setter, function() { 86 | global[type.setter].mockClear(); 87 | global[type.setter].mockReturnValue(1); 88 | global[type.clearer].mockClear(); 89 | var cb = jest.genMockFunction(); 90 | var id = component[type.setter](cb, 10); 91 | expect(cb).not.toBeCalled(); 92 | global[type.setter].mock.calls[0][0](); 93 | expect(cb).toBeCalled(); 94 | 95 | if (type.setter !== 'setInterval') { 96 | expect(global[type.clearer]).toBeCalledWith(id); 97 | expect(component[type.array]).toEqual([]); 98 | } else { 99 | expect(global[type.clearer]).not.toBeCalled(); 100 | expect(component[type.array]).toEqual([id]); 101 | } 102 | }); 103 | }); 104 | 105 | }); 106 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-timer-mixin", 3 | "description": "TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts", 4 | "version": "0.13.4", 5 | "keywords": [ 6 | "react", 7 | "timer", 8 | "mixin" 9 | ], 10 | "bugs": "https://github.com/reactjs/react-timer-mixin/issues", 11 | "license": "MIT", 12 | "main": "TimerMixin.js", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/reactjs/react-timer-mixin.git" 16 | }, 17 | "devDependencies": { 18 | "eslint": "0.9.2", 19 | "jest-cli": "^0.2.1" 20 | }, 21 | "scripts": { 22 | "test": "./node_modules/.bin/jest" 23 | } 24 | } 25 | --------------------------------------------------------------------------------