Last active
July 30, 2018 12:47
-
-
Save marcelopereirascmspain/80f75e97fbce147d149b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery | |
const hashCode = (s) => { | |
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); | |
}; | |
const memoizeObservable = (fn) => { | |
let cache = {}; | |
return (...args) => { | |
let entryKey = hashCode(JSON.stringify(args)); | |
if (cache[entryKey]) { | |
return Rx.Observable.just(cache[entryKey]); | |
} | |
return fn.apply(null, args).map((value) => { | |
cache[entryKey] = value; | |
return value; | |
}, (err) => { | |
return err; | |
}); | |
} | |
}; | |
var memAjax = memoizeObservable(Rx.DOM.ajax); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment