diff options
author | Saivan <savian@me.com> | 2018-11-25 16:21:53 +1300 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-11-25 16:21:53 +1300 |
commit | 62de7d0a1b994b69032a759b796b486e6bc382e3 (patch) | |
tree | 112b19f2903b4dc5b4cf61ebef0d021c6ca2f14d /src/modules/optional/memory.js | |
parent | 2b37d7ba5b4267b39c86f9aba5fb14a1b376e846 (diff) | |
download | svg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.tar.gz svg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.zip |
Changed the esLint rules to avoid silly ternary operators, and to let code breathe!
This commit modifies some of the eslint rules, to allow our code to be a little bit more
readable. This came about because we had a particularly pesky problem, where the code
was indenting ternary operators. This fixes that, and makes it easy to add new rules
to eslint as we please in the future.
Changes
=======
- Rebuilt the library with new eslint rules
- Changed the eslintrc file to a yaml file by default
Diffstat (limited to 'src/modules/optional/memory.js')
-rw-r--r-- | src/modules/optional/memory.js | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/modules/optional/memory.js b/src/modules/optional/memory.js index 6478367..7c599f0 100644 --- a/src/modules/optional/memory.js +++ b/src/modules/optional/memory.js @@ -1,40 +1,60 @@ import { registerMethods } from '../../utils/methods.js' // Remember arbitrary data -export function remember (k, v) { +export function remember ( k, v ) { + // remember every item in an object individually - if (typeof arguments[0] === 'object') { - for (var key in k) { - this.remember(key, k[key]) + if ( typeof arguments[0] === 'object' ) { + + for ( var key in k ) { + + this.remember( key, k[key] ) + } - } else if (arguments.length === 1) { + + } else if ( arguments.length === 1 ) { + // retrieve memory return this.memory()[k] + } else { + // store memory this.memory()[k] = v + } return this + } // Erase a given memory export function forget () { - if (arguments.length === 0) { + + if ( arguments.length === 0 ) { + this._memory = {} + } else { - for (var i = arguments.length - 1; i >= 0; i--) { + + for ( var i = arguments.length - 1; i >= 0; i-- ) { + delete this.memory()[arguments[i]] + } + } return this + } // This triggers creation of a new hidden class which is not performant // However, this function is not rarely used so it will not happen frequently // Return local memory object export function memory () { - return (this._memory = this._memory || {}) + + return ( this._memory = this._memory || {} ) + } -registerMethods('Dom', { remember, forget, memory }) +registerMethods( 'Dom', { remember, forget, memory } ) |