serialize option, for custom args serialization

This commit is contained in:
Mariusz Nowak
2013-07-22 20:37:15 +02:00
parent baae9f8d54
commit 343b6cdcd4
4 changed files with 25 additions and 6 deletions

View File

@@ -33,7 +33,7 @@ module.exports = exports = function (core) {
length = (options.length === false) ? false : (options.length >>> 0);
}
core(conf, length);
core(conf, length, options);
forEach(ext, function (fn, name) {
if (fn.force) fn(conf, options);

View File

@@ -18,5 +18,6 @@ require('./ext/max');
module.exports = function (fn/* options */) {
var options = Object(arguments[1]);
return call.call(options.primitive ? primitive : regular, this, fn, options);
return call.call((options.primitive || options.serialize) ?
primitive : regular, this, fn, options);
};

View File

@@ -3,6 +3,7 @@
'use strict';
var CustomError = require('es5-ext/lib/Error/custom')
, callable = require('es5-ext/lib/Object/valid-callable')
, hasListeners = require('event-emitter/lib/has-listeners')
, serialize0 = function () { return ''; }
@@ -22,11 +23,14 @@ serializeN = function (args) {
return id;
};
module.exports = require('./_base')(function (conf, length) {
module.exports = require('./_base')(function (conf, length, options) {
var get, cache = conf.cache = {}, fn
, hitListeners, initListeners, purgeListeners;
, hitListeners, initListeners, purgeListeners, serialize;
if (length === 1) {
if (options.serialize) {
serialize = callable(options.serialize);
get = conf.get = function (args) { return serialize.apply(this, args); };
} else if (length === 1) {
get = conf.get = serialize1;
} else if (length === false) {
get = conf.get = serializeN;