CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
cache-traversal-call.mjs35 linesDownload Raw Back to collection
1import * as is from '../is.mjs';2import * as util from '../util/index.mjs';3 4let cache = function( fn, name ){5  return function traversalCache( arg1, arg2, arg3, arg4 ){6    let selectorOrEles = arg1;7    let eles = this;8    let key;9 10    if( selectorOrEles == null ){11      key = '';12    } else if( is.elementOrCollection( selectorOrEles ) && selectorOrEles.length === 1 ){13      key = selectorOrEles.id();14    }15 16    if( eles.length === 1 && key ){17      let _p = eles[0]._private;18      let tch = _p.traversalCache = _p.traversalCache || {};19      let ch = tch[ name ] = tch[ name ] || [];20      let hash = util.hashString( key );21      let cacheHit = ch[ hash ];22 23      if( cacheHit ){24        return cacheHit;25      } else {26        return ( ch[ hash ] = fn.call( eles, arg1, arg2, arg3, arg4 ) );27      }28    } else {29      return fn.call( eles, arg1, arg2, arg3, arg4 );30    }31  };32};33 34export default cache;35 
basant307/AI_Governance_Project · CoolFace