Files
memoizee/index.js
Mariusz Nowak eb72d16bf6 Major reorganization and partial refactoring
- Move out main modules from `lib` folder
- Introduce `normalizer` based configurations, and convert primitive and regular handlers into thos normalizers (can be found in lib/normalizers folder). Custom normalizers can be provided at run time via `normaizer` option
- Provide `plain` module which does not load any extensions or normalizers. Any extensions that have to be used should be required upfront and normalizers should be provided directly
- Remove `method` option, instead `methods` and `methods-plan` modules are provided which generate descriptors for lazy created memoized methods
- `profile` is no longer extension. To be used it should be required directly
- Improve logic for `async` handling
- Take out `max` extensionLRU logic into external `lru-queue` package
- Remove `context` option
- Remove possibility to access original arguments when resolvers are used
- Assure expected length of memoized functions
2014-04-27 12:11:06 +02:00

36 lines
1.3 KiB
JavaScript

'use strict';
var normalizeOpts = require('es5-ext/object/normalize-options')
, resolveLength = require('./lib/resolve-length')
, plain = require('./plain');
module.exports = function (fn/*, options*/) {
var options = normalizeOpts(arguments[1]), length;
if (!options.normalizer && !options.serialize) {
length = options.length = resolveLength(options.length, fn.length, options.async);
if (length === 0) {
options.normalizer = require('./lib/normalizers/0');
} else if (options.primitive) {
if (length === false) {
options.normalizer = require('./lib/normalizers/primitive');
} else if (length > 1) {
options.normalizer = require('./lib/normalizers/get-primitive-fixed')(length);
}
} else {
if (length === false) options.normalizer = require('./lib/normalizers/get-regular')();
else if (length === 1) options.normalizer = require('./lib/normalizers/get-regular-1')();
else options.normalizer = require('./lib/normalizers/get-regular-fixed')(length);
}
}
// Assure extensions
if (options.async) require('./ext/async');
if (options.dispose) require('./ext/dispose');
if (options.maxAge) require('./ext/max-age');
if (options.max) require('./ext/max');
if (options.refCounter) require('./ext/ref-counter');
return plain(fn, options);
};