├── .npmignore ├── .gitignore ├── .babelrc ├── LICENSE ├── package.json ├── readme.md ├── test └── main.js ├── src └── index.js ├── lib └── index.js └── .eslintrc /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react-native", "react-native-stage-0"] 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License (ISC) 2 | Copyright <2019> 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 5 | 6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-timer", 3 | "version": "1.3.6", 4 | "description": "something to manage timers in react native", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "babel-node test/main.js", 8 | "build": "npm run clean && babel src/ --out-dir lib/", 9 | "watch": "npm run clean && babel -w src/ --out-dir lib/", 10 | "clean": "rm -rf lib/" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+ssh://git@github.com/fractaltech/react-native-timer.git" 15 | }, 16 | "author": "Kapil ", 17 | "license": "ISC", 18 | "bugs": { 19 | "url": "https://github.com/fractaltech/react-native-timer/issues" 20 | }, 21 | "homepage": "https://github.com/fractaltech/react-native-timer#readme", 22 | "devDependencies": { 23 | "babel-cli": "^6.26.0", 24 | "babel-eslint": "^8.2.6", 25 | "babel-preset-es2015": "^6.24.1", 26 | "babel-preset-react": "^6.5.0", 27 | "babel-preset-react-native-stage-0": "^1.0.1", 28 | "eslint": "^5.15.1", 29 | "eslint-plugin-babel": "^3.1.0", 30 | "eslint-plugin-react": "^4.2.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # react-native-timer 2 | ## We follow [breaking].[feature].[fix] versioning 3 | 4 | `npm install --save react-native-timer` 5 | 6 | #### A better way to manage timers in react-native with ES6 components, using __WeakMap__. 7 | #### Version 1.3.6 8 | 9 | 1. Often you need to do things like show a message for a few seconds, and then hide it, or run an operation again and again at a specific interval. These things will usually happen *inside* a React Component, and will start *after* a component has mounted. So, you really cannot *just* do a `setTimeout(fn, 2000)` for non trivial things. You need to do a `this.timer = setTimeout(fn, 2000)`, and then `clearTimeout(this.timer)` in `componentWillUnmount`. 10 | 11 | 2. When a component unmounts, these timers have to be cleared and, so that you are not left with zombie timers doing things when you did not expect them to be there. 12 | 13 | 3. React, right now, offers a solution using the `react-native-timer-mixin` for this. However, mixins are not part of ES6-7 standard, and probably will never be as they get in the way of good software design. And this brings us to the package in question, `react-native-timer`. 14 | 15 | 4. With `react-native-timer`, you can set different timers, like `timeout`, `interval` etc in the context of a react component, and unmount all of them when the component unmounts, at context level. 16 | 17 | Generic API: 18 | 19 | ```js 20 | const timer = require('react-native-timer'); 21 | 22 | // timers maintained in the Map timer.timeouts 23 | timer.setTimeout(name, fn, interval); 24 | timer.clearTimeout(name); 25 | timer.timeoutExists(name); 26 | 27 | // timers maintained in the Map timer.intervals 28 | timer.setInterval(name, fn, interval); 29 | timer.clearInterval(name); 30 | timer.intervalExists(name); 31 | 32 | // timers maintained in the Map timer.immediates 33 | timer.setImmediate(name, fn); 34 | timer.clearImmediate(name); 35 | timer.immediateExists(name); 36 | 37 | // timers maintained in the Map timer.animationFrames 38 | timer.requestAnimationFrame(name, fn); 39 | timer.cancelAnimationFrame(name); 40 | timer.animationFrameExists(name); 41 | 42 | ``` 43 | 44 | Mostly, using timers is a pain *inside* react-native components, so we present to you 45 | __Contextual Timers__. API: 46 | ```js 47 | 48 | timer.setTimeout(context, name, fn, interval); 49 | timer.clearTimeout(context, name); 50 | timer.clearTimeout(context) // clears all timeouts for a context 51 | timer.timeoutExists(context, name); 52 | 53 | timer.setInterval(context, name, fn, interval); 54 | timer.clearInterval(context, name); 55 | timer.clearInterval(context); // clears all intervals for a context 56 | timer.intervalExists(context, name); 57 | 58 | timer.setImmediate(context, name, fn); 59 | timer.clearImmediate(context, name); 60 | timer.clearImmediate(context); // clears all immediates for a context 61 | timer.immediateExists(context, name); 62 | 63 | timer.requestAnimationFrame(context, name, fn); 64 | timer.cancelAnimationFrame(context, name); 65 | timer.cancelAnimationFrame(context); // cancels all animation frames for a context 66 | timer.animationFrameExists(context, name); 67 | 68 | 69 | ``` 70 | 71 | Example Below: 72 | 73 | ```js 74 | const timer = require('react-native-timer'); 75 | 76 | class Foo extends React.Component { 77 | state = { 78 | showMsg: false 79 | }; 80 | 81 | componentWillUnmount() { 82 | timer.clearTimeout(this); 83 | } 84 | 85 | showMsg() { 86 | this.setState({showMsg: true}, () => timer.setTimeout( 87 | this, 'hideMsg', () => this.setState({showMsg: false}), 2000 88 | )); 89 | } 90 | 91 | render() { 92 | return { 93 | 94 | requestAnimationFrame(() => this.showMsg())}> 95 | Press Me 96 | 97 | 98 | {this.state.showMsg ? ( 99 | Hello!! 100 | ) : ( 101 | null 102 | )} 103 | 104 | } 105 | } 106 | } 107 | 108 | 109 | ``` 110 | 111 | PS: Kinda not a best practice, but `const t = require('react-native-timer')` can cut down some typing. 112 | Also, this lib can be used in browsers too, but will focus on them when I am working with them. 113 | -------------------------------------------------------------------------------- /test/main.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const timer = require('../lib/index'); 3 | 4 | (() => { 5 | let done = false; 6 | timer.setTimeout('testSetTimeout', () => { done = true; }, 100); 7 | 8 | setTimeout(() => { 9 | assert.ok(done && !timer.timeoutExists('testSetTimeout'), 'setTimeout works'); 10 | }, 105); 11 | })(); 12 | 13 | (() => { 14 | const ctx = {}; 15 | let done = false; 16 | timer.setTimeout(ctx, 'testSetTimeoutCtx', () => { done = true; }, 100); 17 | 18 | setTimeout(() => { 19 | assert.ok( 20 | done && !timer.contextTimer(ctx).timeoutExists('testSetTimeout'), 21 | 'setTimeoutCtx works' 22 | ); 23 | }, 105); 24 | })(); 25 | 26 | 27 | (() => { 28 | let done = false; 29 | timer.setTimeout('testClearTimeout', () => { done = true; }, 100); 30 | setTimeout(() => timer.clearTimeout('testClearTimeout'), 50); 31 | 32 | setTimeout(() => { 33 | assert.ok(!done, 'clearTimeout works'); 34 | }, 105); 35 | })(); 36 | 37 | (() => { 38 | const ctx = {}; 39 | let done = false; 40 | timer.setTimeout(ctx, 'testClearTimeoutCtx', () => { done = true; }, 100); 41 | setTimeout(() => timer.clearTimeout(ctx), 50); 42 | 43 | setTimeout(() => { 44 | assert.ok(!done, 'clearTimeoutCtx works'); 45 | }, 105); 46 | })(); 47 | 48 | (() => { 49 | const flags = []; 50 | timer.setInterval('testInterval', () => { flags.push(flags.length); }, 100); 51 | 52 | setTimeout(() => { 53 | assert.ok( 54 | flags.length === 3, 55 | 'setInterval works, if it doesn\'t, modify the timeout of this timeout' 56 | ); 57 | timer.clearInterval('testInterval'); 58 | 59 | setTimeout(() => { 60 | assert.ok(flags.length === 3 && !timer.intervalExists('testInterval'), 'clearInterval works'); 61 | }, 200); 62 | }, 400); 63 | // usually for around 390, this test seems to pass, so setting it greater than that 64 | })(); 65 | 66 | (() => { 67 | const ctx = {}; 68 | const flags = []; 69 | timer.setInterval(ctx, 'testIntervalCtx', () => { flags.push(flags.length); }, 100); 70 | 71 | setTimeout(() => { 72 | assert.ok( 73 | flags.length === 3, 74 | 'setIntervalCtx works, if it doesn\'t, modify the timeout of this timeout' 75 | ); 76 | timer.clearInterval(ctx); 77 | 78 | setTimeout(() => { 79 | assert.ok( 80 | flags.length === 3 && !timer.contextTimer(ctx).intervalExists('testIntervalCtx'), 81 | 'clearIntervalCtx works' 82 | ); 83 | }, 200); 84 | }, 400); 85 | // usually for around 390, this test seems to pass, so setting it greater than that 86 | })(); 87 | 88 | (() => { 89 | const ctx = {}; 90 | const flags = []; 91 | const timerName = 'timerName'; 92 | 93 | timer.setInterval(ctx, timerName, () => { flags.push(flags.length); }, 100); 94 | 95 | setTimeout(() => { 96 | assert.ok( 97 | flags.length === 3, 98 | 'setIntervalCtx works with timerName, if it doesn\'t, modify the timeout of this timeout' 99 | ); 100 | timer.clearInterval(ctx, timerName); 101 | 102 | setTimeout(() => { 103 | assert.ok( 104 | flags.length === 3 && !timer.contextTimer(ctx).intervalExists(timerName), 105 | 'clearIntervalCtx works with timerName works' 106 | ); 107 | }, 200); 108 | }, 400); 109 | // usually for around 390, this test seems to pass, so setting it greater than that 110 | })(); 111 | 112 | 113 | (() => { 114 | let done = false; 115 | timer.setTimeout('testSetImmediate', () => { done = true; }); 116 | 117 | setTimeout(() => { 118 | assert.ok(done && !timer.immediateExists('testSetImmediate'), 'setImmediate works'); 119 | }, 50); 120 | })(); 121 | 122 | (() => { 123 | const ctx = {}; 124 | let done = false; 125 | timer.setTimeout(ctx, 'testSetImmediateCtx', () => { done = true; }); 126 | 127 | setTimeout(() => { 128 | assert.ok( 129 | done && !timer.contextTimer(ctx).immediateExists('testSetImmediateCtx'), 130 | 'setImmediateCtx works' 131 | ); 132 | }, 50); 133 | })(); 134 | 135 | 136 | (() => { 137 | let done = false; 138 | let m = 1; 139 | for (let i=0; i<1000; i=i+1) { 140 | if (i === 0) { 141 | timer.setImmediate('testClearImmediate', () => { done = true; }); 142 | } 143 | 144 | if (i === 5) { 145 | timer.clearImmediate('testClearImmediate'); 146 | } 147 | 148 | m = m*i+1; 149 | } 150 | setTimeout(() => { 151 | assert.ok(!done, 'clearImmediate works'); 152 | }, 50); 153 | })(); 154 | 155 | (() => { 156 | const ctx = {}; 157 | let done = false; 158 | let m = 1; 159 | for (let i=0; i<1000; i=i+1) { 160 | if (i === 0) { 161 | timer.setImmediate(ctx, 'testClearImmediateCtx', () => { done = true; }); 162 | } 163 | 164 | if (i === 5) { 165 | timer.clearImmediate(ctx); 166 | } 167 | 168 | m = m*i+1; 169 | } 170 | setTimeout(() => { 171 | assert.ok(!done, 'clearImmediateCtx works'); 172 | }, 50); 173 | })(); 174 | 175 | 176 | /** 177 | * below two can only be tested in a UI env, but they should work, code is simple, 178 | * so commenting them out for now 179 | */ 180 | 181 | /* 182 | 183 | (() => { 184 | let done = false; 185 | timer.requestAnimationFrame('testRequestAnimationFrame', () => { done = true; }); 186 | 187 | setTimeout(() => { 188 | assert.ok( 189 | done && 190 | !timer.animationFrames.has('testRequestAnimationFrame'), 'requestAnimationFrame works' 191 | ); 192 | }, 50); 193 | })(); 194 | 195 | (() => { 196 | let done = false; 197 | let m = 1; 198 | for (let i=0; i<1000; i=i+1) { 199 | if (i === 0) { 200 | timer.requestAnimationFrame('testCancelRequestAnimationFrame', () => { done = true; }); 201 | } 202 | 203 | if (i === 5) { 204 | timer.cancelAnimationFrame('testCancelRequestAnimationFrame'); 205 | } 206 | 207 | m = m*i+1; 208 | } 209 | setTimeout(() => { 210 | assert.ok(!done, 'cancelAnimationFrame works'); 211 | }, 50); 212 | })(); 213 | 214 | */ 215 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | class Timer { 2 | timeouts = new Map(); 3 | intervals = new Map(); 4 | immediates = new Map(); 5 | animationFrames = new Map(); 6 | 7 | executedTimeouts = new Set(); 8 | executedImmediates = new Set(); 9 | executedAnimationFrames = new Set(); 10 | 11 | contextTimers = new WeakMap(); 12 | 13 | contextTimer(ctx) { 14 | if (!this.contextTimers.has(ctx)) { 15 | this.contextTimers.set(ctx, new Timer()); 16 | } 17 | 18 | return this.contextTimers.get(ctx); 19 | } 20 | 21 | setTimeout(...args) { 22 | if ((typeof args[0]) === 'object') { 23 | return this._setTimeoutContext(...args); 24 | } else { 25 | return this._setTimeoutVanilla(...args); 26 | } 27 | } 28 | 29 | _setTimeoutContext(ctx, name, fn, interval) { 30 | this.contextTimer(ctx).setTimeout(name, fn, interval); 31 | return this; 32 | } 33 | 34 | _setTimeoutVanilla(name, fn, interval) { 35 | this.clearTimeout(name); 36 | this.timeouts.set(name, setTimeout(() => { 37 | this.clearTimeout(name); 38 | this.executedTimeouts.add(name); 39 | fn(); 40 | this.executedTimeouts.delete(name); 41 | }, interval)); 42 | 43 | return this; 44 | } 45 | 46 | clearTimeout(...args) { 47 | if ((typeof args[0]) === 'object') { 48 | return this._clearTimeoutContext(...args); 49 | } else { 50 | return this._clearTimeoutVanilla(...args); 51 | } 52 | } 53 | 54 | _clearTimeoutContext(ctx, ...args) { 55 | if (!this.contextTimers.has(ctx)) { 56 | return this; 57 | } 58 | 59 | if (args.length === 0) { 60 | Array.from(this.contextTimer(ctx).timeouts.keys()).forEach((timeout) => { 61 | this.contextTimer(ctx).clearTimeout(timeout); 62 | }); 63 | } else { 64 | const [timeout] = args; 65 | this.contextTimer(ctx).clearTimeout(timeout); 66 | } 67 | 68 | return this; 69 | } 70 | 71 | _clearTimeoutVanilla(name) { 72 | if (this.timeouts.has(name)) { 73 | clearTimeout(this.timeouts.get(name)); 74 | this.timeouts.delete(name); 75 | } 76 | 77 | return this; 78 | } 79 | 80 | timeoutExists(...args) { 81 | if ((typeof args[0]) === 'object') { 82 | return this._timeoutExistsContext(...args); 83 | } else { 84 | return this._timeoutExistsVanilla(...args); 85 | } 86 | } 87 | 88 | _timeoutExistsContext(ctx, name) { 89 | return this.contextTimers.has(ctx) && this.contextTimer(ctx).timeoutExists(name); 90 | } 91 | 92 | _timeoutExistsVanilla(name) { 93 | return this.timeouts.has(name) || this.executedTimeouts.has(name); 94 | } 95 | 96 | setInterval(...args) { 97 | if ((typeof args[0]) === 'object') { 98 | return this._setIntervalContext(...args); 99 | } else { 100 | return this._setIntervalVanilla(...args); 101 | } 102 | } 103 | 104 | _setIntervalContext(ctx, name, fn, interval) { 105 | this.contextTimer(ctx).setInterval(name, fn, interval); 106 | return this; 107 | } 108 | 109 | _setIntervalVanilla(name, fn, interval) { 110 | this.clearInterval(name); 111 | this.intervals.set(name, setInterval(fn, interval)); 112 | return this; 113 | } 114 | 115 | clearInterval(...args) { 116 | if ((typeof args[0]) === 'object') { 117 | return this._clearIntervalContext(...args); 118 | } else { 119 | return this._clearIntervalVanilla(...args); 120 | } 121 | } 122 | 123 | _clearIntervalContext(ctx, ...args) { 124 | if (!this.contextTimers.has(ctx)) { 125 | return this; 126 | } 127 | 128 | if (args.length === 0) { 129 | Array.from(this.contextTimer(ctx).intervals.keys()).forEach((interval) => { 130 | this.contextTimer(ctx).clearInterval(interval); 131 | }); 132 | } else { 133 | const [interval] = args; 134 | this.contextTimer(ctx).clearInterval(interval); 135 | } 136 | 137 | return this; 138 | } 139 | 140 | _clearIntervalVanilla(name) { 141 | if (this.intervals.has(name)) { 142 | clearInterval(this.intervals.get(name)); 143 | this.intervals.delete(name); 144 | } 145 | 146 | return this; 147 | } 148 | 149 | intervalExists(...args) { 150 | if (typeof args[0] === 'object') { 151 | return this._intervalExistsContext(...args); 152 | } else { 153 | return this._intervalExistsVanilla(...args); 154 | } 155 | } 156 | 157 | _intervalExistsContext(ctx, name) { 158 | return this.contextTimers.has(ctx) && this.contextTimer(ctx).intervalExists(name); 159 | } 160 | 161 | _intervalExistsVanilla(name) { 162 | return this.intervals.has(name); 163 | } 164 | 165 | setImmediate(...args) { 166 | if ((typeof args[0]) === 'object') { 167 | return this._setImmediateContext(...args); 168 | } else { 169 | return this._setImmediateVanilla(...args); 170 | } 171 | } 172 | 173 | _setImmediateContext(ctx, name, fn) { 174 | this.contextTimer(ctx).setImmediate(name, fn); 175 | return this; 176 | } 177 | 178 | _setImmediateVanilla(name, fn) { 179 | this.clearImmediate(name); 180 | this.immediates.set(name, setImmediate(() => { 181 | this.clearImmediate(name); 182 | this.executedImmediates.add(name); 183 | fn(); 184 | this.executedImmediates.delete(name); 185 | })); 186 | 187 | return this; 188 | } 189 | 190 | clearImmediate(...args) { 191 | if ((typeof args[0]) === 'object') { 192 | return this._clearImmediateContext(...args); 193 | } else { 194 | return this._clearImmediateVanilla(...args); 195 | } 196 | } 197 | 198 | _clearImmediateContext(ctx, ...args) { 199 | if (!this.contextTimers.has(ctx)) { 200 | return this; 201 | } 202 | 203 | if (args.length === 0) { 204 | Array.from(this.contextTimer(ctx).immediates.keys()).forEach((immediate) => { 205 | this.contextTimer(ctx).clearImmediate(immediate); 206 | }); 207 | } else { 208 | const [immediate] = args; 209 | this.contextTimer(ctx).clearImmediate(immediate); 210 | } 211 | 212 | return this; 213 | } 214 | 215 | _clearImmediateVanilla(name) { 216 | if (this.immediates.has(name)) { 217 | clearImmediate(this.immediates.get(name)); 218 | this.immediates.delete(name); 219 | } 220 | 221 | return this; 222 | } 223 | 224 | immediateExists(...args) { 225 | if (typeof args[0] === 'object') { 226 | return this._immediateExistsContext(...args); 227 | } else { 228 | return this._immediateExistsVanilla(...args); 229 | } 230 | } 231 | 232 | _immediateExistsContext(ctx, name) { 233 | return this.contextTimers.has(ctx) && this.contextTimer(ctx).immediateExists(name); 234 | } 235 | 236 | _immediateExistsVanilla(name) { 237 | return this.immediates.has(name) || this.executedImmediates.has(name); 238 | } 239 | 240 | requestAnimationFrame(...args) { 241 | if ((typeof args[0]) === 'object') { 242 | return this._requestAnimationFrameContext(...args); 243 | } else { 244 | return this._requestAnimationFrameVanilla(...args); 245 | } 246 | } 247 | 248 | _requestAnimationFrameContext(ctx, name, fn) { 249 | this.contextTimer(ctx).requestAnimationFrame(name, fn); 250 | 251 | return this; 252 | } 253 | 254 | _requestAnimationFrameVanilla(name, fn) { 255 | this.cancelAnimationFrame(name); 256 | this.animationFrames.set(name, requestAnimationFrame(() => { 257 | this.cancelAnimationFrame(name); 258 | this.executedAnimationFrames.add(name); 259 | fn(); 260 | this.executedAnimationFrames.delete(name); 261 | })); 262 | 263 | return this; 264 | } 265 | 266 | cancelAnimationFrame(...args) { 267 | if ((typeof args[0]) === 'object') { 268 | return this._cancelAnimationFrameContext(...args); 269 | } else { 270 | return this._cancelAnimationFrameVanilla(...args); 271 | } 272 | } 273 | 274 | _cancelAnimationFrameContext(ctx, ...args) { 275 | if (!this.contextTimers.has(ctx)) { 276 | return this; 277 | } 278 | 279 | if (args.length === 0) { 280 | Array.from(this.contextTimer(ctx).animationFrames.keys()).forEach((animationFrame) => { 281 | this.contextTimer(ctx).cancelAnimationFrame(animationFrame); 282 | }); 283 | } else { 284 | const [animationFrame] = args; 285 | this.contextTimer(ctx).cancelAnimationFrame(animationFrame); 286 | } 287 | 288 | return this; 289 | } 290 | 291 | _cancelAnimationFrameVanilla(name) { 292 | if (this.animationFrames.has(name)) { 293 | cancelAnimationFrame(this.animationFrames.get(name)); 294 | this.animationFrames.delete(name); 295 | } 296 | 297 | return this; 298 | } 299 | 300 | animationFrameExists(...args) { 301 | if (typeof args[0] === 'object') { 302 | return this._animationFrameExistsContext(...args); 303 | } else { 304 | return this._animationFrameExistsVanilla(...args); 305 | } 306 | } 307 | 308 | _animationFrameExistsContext(ctx, name) { 309 | return this.contextTimers.has(ctx) && this.contextTimer(ctx).animationFrameExists(name); 310 | } 311 | 312 | _animationFrameExistsVanilla(name) { 313 | return this.animationFrames.has(name) || this.executedAnimationFrames.has(name); 314 | } 315 | } 316 | 317 | module.exports = new Timer(); 318 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict';var _typeof=typeof Symbol==="function"&&typeof(typeof Symbol==='function'?Symbol.iterator:'@@iterator')==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==(typeof Symbol==='function'?Symbol.prototype:'@@prototype')?"symbol":typeof obj;};var _createClass=function(){function defineProperties(target,props){for(var i=0;i1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key];} 58 | 59 | if(args.length===0){ 60 | Array.from(this.contextTimer(ctx).timeouts.keys()).forEach(function(timeout){ 61 | _this2.contextTimer(ctx).clearTimeout(timeout); 62 | }); 63 | }else{var 64 | timeout=args[0]; 65 | this.contextTimer(ctx).clearTimeout(timeout); 66 | } 67 | 68 | return this; 69 | }},{key:'_clearTimeoutVanilla',value:function _clearTimeoutVanilla( 70 | 71 | name){ 72 | if(this.timeouts.has(name)){ 73 | clearTimeout(this.timeouts.get(name)); 74 | this.timeouts.delete(name); 75 | } 76 | 77 | return this; 78 | }},{key:'timeoutExists',value:function timeoutExists() 79 | 80 | { 81 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 82 | return this._timeoutExistsContext.apply(this,arguments); 83 | }else{ 84 | return this._timeoutExistsVanilla.apply(this,arguments); 85 | } 86 | }},{key:'_timeoutExistsContext',value:function _timeoutExistsContext( 87 | 88 | ctx,name){ 89 | return this.contextTimers.has(ctx)&&this.contextTimer(ctx).timeoutExists(name); 90 | }},{key:'_timeoutExistsVanilla',value:function _timeoutExistsVanilla( 91 | 92 | name){ 93 | return this.timeouts.has(name)||this.executedTimeouts.has(name); 94 | }},{key:'setInterval',value:function setInterval() 95 | 96 | { 97 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 98 | return this._setIntervalContext.apply(this,arguments); 99 | }else{ 100 | return this._setIntervalVanilla.apply(this,arguments); 101 | } 102 | }},{key:'_setIntervalContext',value:function _setIntervalContext( 103 | 104 | ctx,name,fn,interval){ 105 | this.contextTimer(ctx).setInterval(name,fn,interval); 106 | return this; 107 | }},{key:'_setIntervalVanilla',value:function _setIntervalVanilla( 108 | 109 | name,fn,interval){ 110 | this.clearInterval(name); 111 | this.intervals.set(name,setInterval(fn,interval)); 112 | return this; 113 | }},{key:'clearInterval',value:function clearInterval() 114 | 115 | { 116 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 117 | return this._clearIntervalContext.apply(this,arguments); 118 | }else{ 119 | return this._clearIntervalVanilla.apply(this,arguments); 120 | } 121 | }},{key:'_clearIntervalContext',value:function _clearIntervalContext( 122 | 123 | ctx){var _this3=this; 124 | if(!this.contextTimers.has(ctx)){ 125 | return this; 126 | }for(var _len2=arguments.length,args=Array(_len2>1?_len2-1:0),_key2=1;_key2<_len2;_key2++){args[_key2-1]=arguments[_key2];} 127 | 128 | if(args.length===0){ 129 | Array.from(this.contextTimer(ctx).intervals.keys()).forEach(function(interval){ 130 | _this3.contextTimer(ctx).clearInterval(interval); 131 | }); 132 | }else{var 133 | interval=args[0]; 134 | this.contextTimer(ctx).clearInterval(interval); 135 | } 136 | 137 | return this; 138 | }},{key:'_clearIntervalVanilla',value:function _clearIntervalVanilla( 139 | 140 | name){ 141 | if(this.intervals.has(name)){ 142 | clearInterval(this.intervals.get(name)); 143 | this.intervals.delete(name); 144 | } 145 | 146 | return this; 147 | }},{key:'intervalExists',value:function intervalExists() 148 | 149 | { 150 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 151 | return this._intervalExistsContext.apply(this,arguments); 152 | }else{ 153 | return this._intervalExistsVanilla.apply(this,arguments); 154 | } 155 | }},{key:'_intervalExistsContext',value:function _intervalExistsContext( 156 | 157 | ctx,name){ 158 | return this.contextTimers.has(ctx)&&this.contextTimer(ctx).intervalExists(name); 159 | }},{key:'_intervalExistsVanilla',value:function _intervalExistsVanilla( 160 | 161 | name){ 162 | return this.intervals.has(name); 163 | }},{key:'setImmediate',value:function setImmediate() 164 | 165 | { 166 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 167 | return this._setImmediateContext.apply(this,arguments); 168 | }else{ 169 | return this._setImmediateVanilla.apply(this,arguments); 170 | } 171 | }},{key:'_setImmediateContext',value:function _setImmediateContext( 172 | 173 | ctx,name,fn){ 174 | this.contextTimer(ctx).setImmediate(name,fn); 175 | return this; 176 | }},{key:'_setImmediateVanilla',value:function _setImmediateVanilla( 177 | 178 | name,fn){var _this4=this; 179 | this.clearImmediate(name); 180 | this.immediates.set(name,setImmediate(function(){ 181 | _this4.clearImmediate(name); 182 | _this4.executedImmediates.add(name); 183 | fn(); 184 | _this4.executedImmediates.delete(name); 185 | })); 186 | 187 | return this; 188 | }},{key:'clearImmediate',value:function clearImmediate() 189 | 190 | { 191 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 192 | return this._clearImmediateContext.apply(this,arguments); 193 | }else{ 194 | return this._clearImmediateVanilla.apply(this,arguments); 195 | } 196 | }},{key:'_clearImmediateContext',value:function _clearImmediateContext( 197 | 198 | ctx){var _this5=this; 199 | if(!this.contextTimers.has(ctx)){ 200 | return this; 201 | }for(var _len3=arguments.length,args=Array(_len3>1?_len3-1:0),_key3=1;_key3<_len3;_key3++){args[_key3-1]=arguments[_key3];} 202 | 203 | if(args.length===0){ 204 | Array.from(this.contextTimer(ctx).immediates.keys()).forEach(function(immediate){ 205 | _this5.contextTimer(ctx).clearImmediate(immediate); 206 | }); 207 | }else{var 208 | immediate=args[0]; 209 | this.contextTimer(ctx).clearImmediate(immediate); 210 | } 211 | 212 | return this; 213 | }},{key:'_clearImmediateVanilla',value:function _clearImmediateVanilla( 214 | 215 | name){ 216 | if(this.immediates.has(name)){ 217 | clearImmediate(this.immediates.get(name)); 218 | this.immediates.delete(name); 219 | } 220 | 221 | return this; 222 | }},{key:'immediateExists',value:function immediateExists() 223 | 224 | { 225 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 226 | return this._immediateExistsContext.apply(this,arguments); 227 | }else{ 228 | return this._immediateExistsVanilla.apply(this,arguments); 229 | } 230 | }},{key:'_immediateExistsContext',value:function _immediateExistsContext( 231 | 232 | ctx,name){ 233 | return this.contextTimers.has(ctx)&&this.contextTimer(ctx).immediateExists(name); 234 | }},{key:'_immediateExistsVanilla',value:function _immediateExistsVanilla( 235 | 236 | name){ 237 | return this.immediates.has(name)||this.executedImmediates.has(name); 238 | }},{key:'requestAnimationFrame',value:function requestAnimationFrame() 239 | 240 | { 241 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 242 | return this._requestAnimationFrameContext.apply(this,arguments); 243 | }else{ 244 | return this._requestAnimationFrameVanilla.apply(this,arguments); 245 | } 246 | }},{key:'_requestAnimationFrameContext',value:function _requestAnimationFrameContext( 247 | 248 | ctx,name,fn){ 249 | this.contextTimer(ctx).requestAnimationFrame(name,fn); 250 | 251 | return this; 252 | }},{key:'_requestAnimationFrameVanilla',value:function _requestAnimationFrameVanilla( 253 | 254 | name,fn){var _this6=this; 255 | this.cancelAnimationFrame(name); 256 | this.animationFrames.set(name,requestAnimationFrame(function(){ 257 | _this6.cancelAnimationFrame(name); 258 | _this6.executedAnimationFrames.add(name); 259 | fn(); 260 | _this6.executedAnimationFrames.delete(name); 261 | })); 262 | 263 | return this; 264 | }},{key:'cancelAnimationFrame',value:function cancelAnimationFrame() 265 | 266 | { 267 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 268 | return this._cancelAnimationFrameContext.apply(this,arguments); 269 | }else{ 270 | return this._cancelAnimationFrameVanilla.apply(this,arguments); 271 | } 272 | }},{key:'_cancelAnimationFrameContext',value:function _cancelAnimationFrameContext( 273 | 274 | ctx){var _this7=this; 275 | if(!this.contextTimers.has(ctx)){ 276 | return this; 277 | }for(var _len4=arguments.length,args=Array(_len4>1?_len4-1:0),_key4=1;_key4<_len4;_key4++){args[_key4-1]=arguments[_key4];} 278 | 279 | if(args.length===0){ 280 | Array.from(this.contextTimer(ctx).animationFrames.keys()).forEach(function(animationFrame){ 281 | _this7.contextTimer(ctx).cancelAnimationFrame(animationFrame); 282 | }); 283 | }else{var 284 | animationFrame=args[0]; 285 | this.contextTimer(ctx).cancelAnimationFrame(animationFrame); 286 | } 287 | 288 | return this; 289 | }},{key:'_cancelAnimationFrameVanilla',value:function _cancelAnimationFrameVanilla( 290 | 291 | name){ 292 | if(this.animationFrames.has(name)){ 293 | cancelAnimationFrame(this.animationFrames.get(name)); 294 | this.animationFrames.delete(name); 295 | } 296 | 297 | return this; 298 | }},{key:'animationFrameExists',value:function animationFrameExists() 299 | 300 | { 301 | if(_typeof(arguments.length<=0?undefined:arguments[0])==='object'){ 302 | return this._animationFrameExistsContext.apply(this,arguments); 303 | }else{ 304 | return this._animationFrameExistsVanilla.apply(this,arguments); 305 | } 306 | }},{key:'_animationFrameExistsContext',value:function _animationFrameExistsContext( 307 | 308 | ctx,name){ 309 | return this.contextTimers.has(ctx)&&this.contextTimer(ctx).animationFrameExists(name); 310 | }},{key:'_animationFrameExistsVanilla',value:function _animationFrameExistsVanilla( 311 | 312 | name){ 313 | return this.animationFrames.has(name)||this.executedAnimationFrames.has(name); 314 | }}]);return Timer;}(); 315 | 316 | 317 | module.exports=new Timer(); -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | 4 | "env": { 5 | "browser": true, 6 | "node": true, 7 | "es6": true 8 | }, 9 | 10 | "plugins": ["react"], 11 | 12 | "ecmaFeatures": { 13 | "arrowFunctions": true, 14 | "binaryLiterals": true, 15 | "blockBindings": true, 16 | "classes": true, 17 | "defaultParams": true, 18 | "destructuring": true, 19 | "forOf": true, 20 | "generators": true, 21 | "modules": true, 22 | "objectLiteralComputedProperties": true, 23 | "objectLiteralDuplicateProperties": true, 24 | "objectLiteralShorthandMethods": true, 25 | "objectLiteralShorthandProperties": true, 26 | "octalLiterals": true, 27 | "regexUFlag": true, 28 | "regexYFlag": true, 29 | "spread": true, 30 | "superInFunctions": true, 31 | "templateStrings": true, 32 | "unicodeCodePointEscapes": true, 33 | "globalReturn": true, 34 | "jsx": true 35 | }, 36 | 37 | "rules": { 38 | 39 | // 40 | //Possible Errors 41 | // 42 | // The following rules point out areas where you might have made mistakes. 43 | // 44 | "comma-dangle": 2, // disallow or enforce trailing commas 45 | "no-cond-assign": 2, // disallow assignment in conditional expressions 46 | "no-console": 0, // disallow use of console (off by default in the node environment) 47 | "no-constant-condition": 2, // disallow use of constant expressions in conditions 48 | "no-control-regex": 2, // disallow control characters in regular expressions 49 | "no-debugger": 2, // disallow use of debugger 50 | "no-dupe-args": 2, // disallow duplicate arguments in functions 51 | "no-dupe-keys": 2, // disallow duplicate keys when creating object literals 52 | "no-duplicate-case": 2, // disallow a duplicate case label. 53 | "no-empty": 2, // disallow empty statements 54 | "no-empty-character-class": 2, // disallow the use of empty character classes in regular expressions 55 | "no-ex-assign": 2, // disallow assigning to the exception in a catch block 56 | "no-extra-boolean-cast": 2, // disallow double-negation boolean casts in a boolean context 57 | "no-extra-parens": 0, // disallow unnecessary parentheses (off by default) 58 | "no-extra-semi": 2, // disallow unnecessary semicolons 59 | "no-func-assign": 2, // disallow overwriting functions written as function declarations 60 | "no-inner-declarations": 2, // disallow function or variable declarations in nested blocks 61 | "no-invalid-regexp": 2, // disallow invalid regular expression strings in the RegExp constructor 62 | "no-irregular-whitespace": 2, // disallow irregular whitespace outside of strings and comments 63 | "no-negated-in-lhs": 2, // disallow negation of the left operand of an in expression 64 | "no-obj-calls": 2, // disallow the use of object properties of the global object (Math and JSON) as functions 65 | "no-regex-spaces": 2, // disallow multiple spaces in a regular expression literal 66 | "no-sparse-arrays": 2, // disallow sparse arrays 67 | "no-unreachable": 2, // disallow unreachable statements after a return, throw, continue, or break statement 68 | "use-isnan": 2, // disallow comparisons with the value NaN 69 | "valid-jsdoc": 2, // Ensure JSDoc comments are valid (off by default) 70 | "valid-typeof": 2, // Ensure that the results of typeof are compared against a valid string 71 | 72 | // 73 | // Best Practices 74 | // 75 | // These are rules designed to prevent you from making mistakes. 76 | // They either prescribe a better way of doing something or help you avoid footguns. 77 | // 78 | "block-scoped-var": 0, // treat var statements as if they were block scoped (off by default). 0: deep destructuring is not compatible https://github.com/eslint/eslint/issues/1863 79 | "complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default) 80 | "consistent-return": 2, // require return statements to either always or never specify values 81 | "curly": 2, // specify curly brace conventions for all control statements 82 | "default-case": 2, // require default case in switch statements (off by default) 83 | "dot-notation": 2, // encourages use of dot notation whenever possible 84 | "eqeqeq": 2, // require the use of === and !== 85 | "guard-for-in": 2, // make sure for-in loops have an if statement (off by default) 86 | "no-alert": 2, // disallow the use of alert, confirm, and prompt 87 | "no-caller": 2, // disallow use of arguments.caller or arguments.callee 88 | "no-div-regex": 2, // disallow division operators explicitly at beginning of regular expression (off by default) 89 | "no-eq-null": 2, // disallow comparisons to null without a type-checking operator (off by default) 90 | "no-eval": 2, // disallow use of eval() 91 | "no-extend-native": 2, // disallow adding to native types 92 | "no-extra-bind": 2, // disallow unnecessary function binding 93 | "no-fallthrough": 2, // disallow fallthrough of case statements 94 | "no-floating-decimal": 2, // disallow the use of leading or trailing decimal points in numeric literals (off by default) 95 | "no-implied-eval": 2, // disallow use of eval()-like methods 96 | "no-iterator": 2, // disallow usage of __iterator__ property 97 | "no-labels": 2, // disallow use of labeled statements 98 | "no-lone-blocks": 2, // disallow unnecessary nested blocks 99 | /*"no-loop-func": 2, // disallow creation of functions within loops*/ 100 | "no-multi-spaces": 2, // disallow use of multiple spaces 101 | "no-multi-str": 2, // disallow use of multiline strings 102 | "no-native-reassign": 2, // disallow reassignments of native objects 103 | "no-new": 2, // disallow use of new operator when not part of the assignment or comparison 104 | "no-new-func": 2, // disallow use of new operator for Function object 105 | "no-new-wrappers": 2, // disallows creating new instances of String,Number, and Boolean 106 | "no-octal": 2, // disallow use of octal literals 107 | "no-octal-escape": 2, // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251"; 108 | "no-process-env": 2, // disallow use of process.env (off by default) 109 | "no-proto": 2, // disallow usage of __proto__ property 110 | "no-redeclare": 2, // disallow declaring the same variable more then once 111 | "no-return-assign": 2, // disallow use of assignment in return statement 112 | "no-script-url": 2, // disallow use of javascript: urls. 113 | "no-self-compare": 2, // disallow comparisons where both sides are exactly the same (off by default) 114 | "no-sequences": 2, // disallow use of comma operator 115 | "no-throw-literal": 2, // restrict what can be thrown as an exception (off by default) 116 | "no-unused-expressions": 2, // disallow usage of expressions in statement position 117 | "no-void": 2, // disallow use of void operator (off by default) 118 | "no-warning-comments": [0, {"terms": ["todo", "fixme"], "location": "start"}], // disallow usage of configurable warning terms in comments": 2, // e.g. TODO or FIXME (off by default) 119 | "no-with": 2, // disallow use of the with statement 120 | "radix": 2, // require use of the second argument for parseInt() (off by default) 121 | "vars-on-top": 2, // requires to declare all vars on top of their containing scope (off by default) 122 | "wrap-iife": 2, // require immediate function invocation to be wrapped in parentheses (off by default) 123 | "yoda": 2, // require or disallow Yoda conditions 124 | 125 | // 126 | // Strict Mode 127 | // 128 | // These rules relate to using strict mode. 129 | // 130 | "strict": 0, // controls location of Use Strict Directives. 0: required by `babel-eslint` 131 | 132 | // 133 | // Variables 134 | // 135 | // These rules have to do with variable declarations. 136 | // 137 | "no-catch-shadow": 2, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment) 138 | "no-delete-var": 2, // disallow deletion of variables 139 | "no-label-var": 2, // disallow labels that share a name with a variable 140 | "no-undef": 2, // disallow use of undeclared variables unless mentioned in a /*global */ block 141 | "no-undef-init": 2, // disallow use of undefined when initializing variables 142 | "no-undefined": 2, // disallow use of undefined variable (off by default) 143 | "no-unused-vars": 2, // disallow declaration of variables that are not used in the code 144 | 145 | // 146 | //Stylistic Issues 147 | // 148 | // These rules are purely matters of style and are quite subjective. 149 | // 150 | "indent": [1, 2], // this option sets a specific tab width for your code (off by default) 151 | /*"brace-style": 1, // enforce one true brace style (off by default)*/ 152 | "comma-spacing": [1, {"before": false, "after": true}], // enforce spacing before and after comma 153 | "comma-style": [1, "last"], // enforce one true comma style (off by default) 154 | "consistent-this": [1, "_this"], // enforces consistent naming when capturing the current execution context (off by default) 155 | "eol-last": 1, // enforce newline at the end of file, with no multiple empty lines 156 | "func-names": 0, // require function expressions to have a name (off by default) 157 | "func-style": 0, // enforces use of function declarations or expressions (off by default) 158 | "key-spacing": [1, {"beforeColon": false, "afterColon": true}], // enforces spacing between keys and values in object literal properties 159 | "max-nested-callbacks": [1, 3], // specify the maximum depth callbacks can be nested (off by default) 160 | "new-cap": [1, {newIsCap: true, capIsNew: false}], // require a capital letter for constructors 161 | "new-parens": 1, // disallow the omission of parentheses when invoking a constructor with no arguments 162 | "newline-after-var": 0, // allow/disallow an empty newline after var statement (off by default) 163 | "no-array-constructor": 1, // disallow use of the Array constructor 164 | "no-inline-comments": 1, // disallow comments inline after code (off by default) 165 | "no-lonely-if": 1, // disallow if as the only statement in an else block (off by default) 166 | "no-mixed-spaces-and-tabs": 1, // disallow mixed spaces and tabs for indentation 167 | "no-multiple-empty-lines": [1, {"max": 2}], // disallow multiple empty lines (off by default) 168 | "no-new-object": 1, // disallow use of the Object constructor 169 | "no-spaced-func": 1, // disallow space between function identifier and application 170 | "no-ternary": 0, // disallow the use of ternary operators (off by default) 171 | "no-trailing-spaces": 1, // disallow trailing whitespace at the end of lines 172 | // "no-underscore-dangle": 1, // disallow dangling underscores in identifiers 173 | "one-var": [1, "never"], // allow just one var statement per function (off by default) 174 | "operator-assignment": [1, "never"], // require assignment operator shorthand where possible or prohibit it entirely (off by default) 175 | "padded-blocks": [1, "never"], // enforce padding within blocks (off by default) 176 | "quote-props": [1, "as-needed"], // require quotes around object literal property names (off by default) 177 | "quotes": [1, "single"], // specify whether double or single quotes should be used 178 | "semi": [1, "always"], // require or disallow use of semicolons instead of ASI 179 | "semi-spacing": [1, {"before": false, "after": true}], // enforce spacing before and after semicolons 180 | "sort-vars": 0, // sort variables within the same declaration block (off by default) 181 | "space-before-blocks": [1, "always"], // require or disallow space before blocks (off by default) 182 | "space-before-function-paren": [1, {"anonymous": "always", "named": "never"}], // require or disallow space before function opening parenthesis (off by default) 183 | "computed-property-spacing": [2, "never"], 184 | "array-bracket-spacing": [2, "never"], 185 | "object-curly-spacing": [2, "never"], 186 | "space-in-parens": [1, "never"], // require or disallow spaces inside parentheses (off by default) 187 | "space-unary-ops": [1, {"words": true, "nonwords": false}], // Require or disallow spaces before/after unary operators (words on by default, nonwords off by default) 188 | "spaced-comment": [2, "always"], // require or disallow a space immediately following the // in a line comment (off by default) 189 | "wrap-regex": 0, // require regex literals to be wrapped in parentheses (off by default) 190 | 191 | // 192 | // ECMAScript 6 193 | // 194 | // These rules are only relevant to ES6 environments and are off by default. 195 | // 196 | "no-var": 2, // require let or const instead of var (off by default) 197 | "generator-star-spacing": [2, "before"], // enforce the spacing around the * in generator functions (off by default) 198 | 199 | // 200 | // Legacy 201 | // 202 | // The following rules are included for compatibility with JSHint and JSLint. 203 | // While the names of the rules may not match up with the JSHint/JSLint counterpart, 204 | // the functionality is the same. 205 | // 206 | "max-depth": [2, 3], // specify the maximum depth that blocks can be nested (off by default) 207 | "max-len": [2, 100, 2], // specify the maximum length of a line in your program (off by default) 208 | "max-params": [2, 5], // limits the number of parameters that can be used in the function declaration. (off by default) 209 | "max-statements": 0, // specify the maximum number of statement allowed in a function (off by default) 210 | "no-bitwise": 0, // disallow use of bitwise operators (off by default) 211 | "no-plusplus": 2, // disallow use of unary operators, ++ and -- (off by default) 212 | 213 | // 214 | // eslint-plugin-react 215 | // 216 | // React specific linting rules for ESLint 217 | // 218 | "react/display-name": 0, // Prevent missing displayName in a React component definition 219 | "jsx-quotes": [2, "prefer-double"], // Enforce quote style for JSX attributes 220 | "react/jsx-no-undef": 2, // Disallow undeclared variables in JSX 221 | "react/jsx-sort-props": 0, // Enforce props alphabetical sorting 222 | "react/jsx-uses-react": 2, // Prevent React to be incorrectly marked as unused 223 | "react/jsx-uses-vars": 2, // Prevent variables used in JSX to be incorrectly marked as unused 224 | "react/no-did-mount-set-state": 2, // Prevent usage of setState in componentDidMount 225 | "react/no-did-update-set-state": 2, // Prevent usage of setState in componentDidUpdate 226 | "react/no-multi-comp": 0, // Prevent multiple component definition per file 227 | "react/no-unknown-property": 2, // Prevent usage of unknown DOM property 228 | "react/prop-types": 2, // Prevent missing props validation in a React component definition 229 | "react/react-in-jsx-scope": 2, // Prevent missing React when using JSX 230 | "react/self-closing-comp": 2, // Prevent extra closing tags for components without children 231 | "react/wrap-multilines": 2, // Prevent missing parentheses around multilines JSX 232 | } 233 | } 234 | --------------------------------------------------------------------------------