Debian Codegraph @

memoizee/normalizers/get-1.js

raw
1 "use strict";
2
3 var indexOf = require("es5-ext/array/#/e-index-of");
4
5 module.exports = function () {
6 var lastId = 0, argsMap = [], cache = [];
7 return {
8 get: function (args) {
9 var index = indexOf.call(argsMap, args[0]);
10 return index === -1 ? null : cache[index];
11 },
12 set: function (args) {
13 argsMap.push(args[0]);
14 cache.push(++lastId);
15 return lastId;
16 },
17 delete: function (id) {
18 var index = indexOf.call(cache, id);
19 if (index !== -1) {
20 argsMap.splice(index, 1);
21 cache.splice(index, 1);
22 }
23 },
24 clear: function () {
25 argsMap = [];
26 cache = [];
27 },
28 };
29 };