| 1 |
"use strict"; |
| 2 |
|
| 3 |
var forEach = require("es5-ext/object/for-each") |
| 4 |
, normalizeOpts = require("es5-ext/object/normalize-options") |
| 5 |
, callable = require("es5-ext/object/valid-callable") |
| 6 |
, lazy = require("d/lazy") |
| 7 |
, resolveLength = require("./resolve-length") |
| 8 |
, extensions = require("./registered-extensions"); |
| 9 |
|
| 10 |
module.exports = function (memoize) { |
| 11 |
return function (props) { |
| 12 |
forEach(props, function (desc) { |
| 13 |
var fn = callable(desc.value), length; |
| 14 |
desc.value = function (options) { |
| 15 |
if (options.getNormalizer) { |
| 16 |
options = normalizeOpts(options); |
| 17 |
if (length === undefined) { |
| 18 |
length = resolveLength( |
| 19 |
options.length, fn.length, options.async && extensions.async |
| 20 |
); |
| 21 |
} |
| 22 |
options.normalizer = options.getNormalizer(length); |
| 23 |
delete options.getNormalizer; |
| 24 |
} |
| 25 |
return memoize(fn.bind(this), options); |
| 26 |
}; |
| 27 |
}); |
| 28 |
return lazy(props); |
| 29 |
}; |
| 30 |
}; |