mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
Improve result emit
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
'use strict';
|
||||
|
||||
var aFrom = require('es5-ext/array/from')
|
||||
, objectMap = require('es5-ext/object/map')
|
||||
, mixin = require('es5-ext/object/mixin')
|
||||
, defineLength = require('es5-ext/function/_define-length')
|
||||
, nextTick = require('next-tick')
|
||||
@@ -134,13 +135,15 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
|
||||
if (!cache[id]) return;
|
||||
result = cache[id];
|
||||
delete cache[id];
|
||||
conf.emit('deleteasync', id, result);
|
||||
conf.emit('deleteasync', id, slice.call(result.args, 1));
|
||||
});
|
||||
|
||||
// On clear
|
||||
conf.on('clear', function () {
|
||||
var oldCache = cache;
|
||||
cache = create(null);
|
||||
conf.emit('clearasync', oldCache);
|
||||
conf.emit('clearasync', objectMap(oldCache, function (data) {
|
||||
return slice.call(data.args, 1);
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -6,14 +6,14 @@ var callable = require('es5-ext/object/valid-callable')
|
||||
, forEach = require('es5-ext/object/for-each')
|
||||
, extensions = require('../lib/registered-extensions')
|
||||
|
||||
, slice = Array.prototype.slice, apply = Function.prototype.apply;
|
||||
, apply = Function.prototype.apply;
|
||||
|
||||
extensions.dispose = function (dispose, conf, options) {
|
||||
var del;
|
||||
callable(dispose);
|
||||
if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
|
||||
conf.on('deleteasync', del = function (id, result) {
|
||||
apply.call(dispose, null, slice.call(result.args, 1));
|
||||
conf.on('deleteasync', del = function (id, resultArray) {
|
||||
apply.call(dispose, null, resultArray);
|
||||
});
|
||||
conf.on('clearasync', function (cache) {
|
||||
forEach(cache, function (result, id) { del(id, result); });
|
||||
|
||||
Reference in New Issue
Block a user