Ox.cache: extend options only once
This commit is contained in:
parent
fe40220d0b
commit
adea34c84e
1 changed files with 29 additions and 29 deletions
|
@ -16,16 +16,16 @@ Ox.cache <f> Memoize a function
|
|||
@*/
|
||||
// TODO: add async test
|
||||
Ox.cache = function(fn, options) {
|
||||
var cache = {},
|
||||
ret = function() {
|
||||
var cache = {}, ret;
|
||||
options = Ox.extend({
|
||||
async: false,
|
||||
key: JSON.stringify
|
||||
}, options || {});
|
||||
var args = Ox.toArray(arguments), key = options.key(args);
|
||||
ret = function() {
|
||||
var args = Ox.slice(arguments), key = options.key(args);
|
||||
function callback() {
|
||||
// cache all arguments passed to callback
|
||||
cache[key] = Ox.toArray(arguments);
|
||||
cache[key] = Ox.slice(arguments);
|
||||
// call the original callback
|
||||
Ox.last(args).apply(this, arguments);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ Ox.queue = function(fn, maxThreads) {
|
|||
processing = [],
|
||||
queued = [],
|
||||
ret = Ox.cache(function() {
|
||||
var args = Ox.toArray(arguments);
|
||||
var args = Ox.slice(arguments);
|
||||
queued.push({args: args, key: getKey(args)});
|
||||
process();
|
||||
}, {async: true, key: getKey}),
|
||||
|
|
Loading…
Reference in a new issue