diff options
Diffstat (limited to 'src/modules/optional/memory.js')
-rw-r--r-- | src/modules/optional/memory.js | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/src/modules/optional/memory.js b/src/modules/optional/memory.js index 7c599f0..6478367 100644 --- a/src/modules/optional/memory.js +++ b/src/modules/optional/memory.js @@ -1,60 +1,40 @@ 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 }) |