You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@fluentui-react-native/memo-cache

Package Overview
Dependencies
Maintainers
6
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluentui-react-native/memo-cache - npm Package Compare versions

Comparing version

to
1.3.4

eslint.config.js

25

CHANGELOG.json

@@ -5,3 +5,26 @@ {

{
"date": "Wed, 29 Jan 2025 18:37:51 GMT",
"date": "Thu, 10 Jul 2025 20:30:36 GMT",
"version": "1.3.4",
"tag": "@fluentui-react-native/memo-cache_v1.3.4",
"comments": {
"patch": [
{
"author": "jasonmo@microsoft.com",
"package": "@fluentui-react-native/memo-cache",
"commit": "479b93cea460a26df70c55b5d3335927ed374713",
"comment": "update builds to use node16 settings and modern export maps"
}
],
"none": [
{
"author": "jasonmo@microsoft.com",
"package": "@fluentui-react-native/memo-cache",
"commit": "54087dca787180bbf34630470cd0d06e88366b30",
"comment": "update eslint to 9.x and use new flat config format with security rules"
}
]
}
},
{
"date": "Wed, 29 Jan 2025 18:42:24 GMT",
"version": "1.3.3",

@@ -8,0 +31,0 @@ "tag": "@fluentui-react-native/memo-cache_v1.3.3",

# Change Log - @fluentui-react-native/memo-cache
<!-- This log was last generated on Wed, 29 Jan 2025 18:37:51 GMT and should not be manually modified. -->
<!-- This log was last generated on Thu, 10 Jul 2025 20:30:36 GMT and should not be manually modified. -->
<!-- Start content -->
## 1.3.4
Thu, 10 Jul 2025 20:30:36 GMT
### Patches
- update builds to use node16 settings and modern export maps (jasonmo@microsoft.com)
## 1.3.3
Wed, 29 Jan 2025 18:37:51 GMT
Wed, 29 Jan 2025 18:42:24 GMT

@@ -11,0 +19,0 @@ ### Patches

8

lib-commonjs/getCacheEntry.js

@@ -31,8 +31,8 @@ "use strict";

// eslint-disable-next-line @typescript-eslint/ban-types
var byObj = (entry.obj = entry.obj || new WeakMap());
const byObj = (entry.obj = entry.obj || new WeakMap());
return byObj.get(val) || byObj.set(val, {}).get(val);
}
// otherwise convert everything to a string and store it in the str object (using it as a map)
var key = val + '';
var byString = ensureAndReturn(entry, 'str');
const key = val + '';
const byString = ensureAndReturn(entry, 'str');
return (byString[key] = byString[key] || {});

@@ -51,3 +51,3 @@ }

return args && args.length > 0
? args.reduce(function (previous, arg) { return jumpToCacheEntry(previous, arg); }, entry)
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
: ensureAndReturn(entry, 'noargs');

@@ -54,0 +54,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var getCacheEntry_1 = require("./getCacheEntry");
const getCacheEntry_1 = require("./getCacheEntry");
function compareResults(base, args, argsNoMatch) {
var e1 = (0, getCacheEntry_1.getCacheEntry)(base, args);
const e1 = (0, getCacheEntry_1.getCacheEntry)(base, args);
expect((0, getCacheEntry_1.getCacheEntry)(base, args)).toBe(e1);

@@ -12,50 +11,50 @@ if (argsNoMatch) {

}
describe('Memo cache unit tests', function () {
test('undefined args to return noargs', function () {
var base = {};
describe('Memo cache unit tests', () => {
test('undefined args to return noargs', () => {
const base = {};
expect((0, getCacheEntry_1.getCacheEntry)(base, undefined)).toBe(base.noargs);
});
test('empty args array to return noargs entry', function () {
var base = {};
test('empty args array to return noargs entry', () => {
const base = {};
expect((0, getCacheEntry_1.getCacheEntry)(base, [])).toBe(base.noargs);
});
test('undefined goes to empty entry', function () {
var base = {};
test('undefined goes to empty entry', () => {
const base = {};
expect((0, getCacheEntry_1.getCacheEntry)(base, [undefined])).toBe(base.empty);
});
test('null to go to empty entry', function () {
var base = {};
test('null to go to empty entry', () => {
const base = {};
expect((0, getCacheEntry_1.getCacheEntry)(base, [null])).toBe(base.empty);
});
test('string gets keyed correctly', function () {
var base = {};
var key = 'foo';
test('string gets keyed correctly', () => {
const base = {};
const key = 'foo';
expect((0, getCacheEntry_1.getCacheEntry)(base, [key])).toBe(base.str[key]);
});
test('number gets keyed correctly', function () {
var base = {};
var val = 235;
var key = val + '';
test('number gets keyed correctly', () => {
const base = {};
const val = 235;
const key = val + '';
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
});
test('bool gets keyed correctly', function () {
var base = {};
var val = true;
var key = val + '';
test('bool gets keyed correctly', () => {
const base = {};
const val = true;
const key = val + '';
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
});
test('false bool gets keyed correctly', function () {
var base = {};
var val = false;
var key = val + '';
test('false bool gets keyed correctly', () => {
const base = {};
const val = false;
const key = val + '';
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
});
test('object gets keyed correctly', function () {
var base = {};
var key = {};
test('object gets keyed correctly', () => {
const base = {};
const key = {};
expect((0, getCacheEntry_1.getCacheEntry)(base, [key])).toBe(base.obj.get(key));
});
test('function gets keyed correctly', function () {
var base = {};
var key = function () {
test('function gets keyed correctly', () => {
const base = {};
const key = () => {
return 'hello world';

@@ -65,36 +64,36 @@ };

});
test('basic string retrieval', function () {
test('basic string retrieval', () => {
compareResults({}, ['hello', 'world'], ['hello world']);
});
test('mixed keys with strings', function () {
test('mixed keys with strings', () => {
compareResults({}, ['hello', 1, true, undefined, 'world'], ['hello', 1, true, '', 'world']);
});
test('basic object matches', function () {
var obj = {};
test('basic object matches', () => {
const obj = {};
compareResults({}, [obj]);
});
test('mixed object and string matches', function () {
var obj = {};
test('mixed object and string matches', () => {
const obj = {};
compareResults({}, [obj, 'hello', 1, 'world']);
});
test('mixed obj and strings with obj at end', function () {
var obj = {};
var obj2 = {};
test('mixed obj and strings with obj at end', () => {
const obj = {};
const obj2 = {};
compareResults({}, ['hello', 1, 'world', obj], ['hello', 1, 'world', obj2]);
});
test('hybrid sets', function () {
var obj = {};
var obj2 = {};
test('hybrid sets', () => {
const obj = {};
const obj2 = {};
compareResults({}, ['hello', obj, 'world', 1, false, obj2, undefined]);
});
test('sub cache on object', function () {
var obj = {};
var args1 = ['hello', obj];
var base = {};
var subRoot = (0, getCacheEntry_1.getCacheEntry)(base, args1);
var args2 = ['world', base];
var target = (0, getCacheEntry_1.getCacheEntry)(subRoot, args2);
expect((0, getCacheEntry_1.getCacheEntry)(base, tslib_1.__spreadArray(tslib_1.__spreadArray([], args1, true), args2, true))).toBe(target);
test('sub cache on object', () => {
const obj = {};
const args1 = ['hello', obj];
const base = {};
const subRoot = (0, getCacheEntry_1.getCacheEntry)(base, args1);
const args2 = ['world', base];
const target = (0, getCacheEntry_1.getCacheEntry)(subRoot, args2);
expect((0, getCacheEntry_1.getCacheEntry)(base, [...args1, ...args2])).toBe(target);
});
});
//# sourceMappingURL=getCacheEntry.test.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMemoCache = void 0;
var getCacheEntry_1 = require("./getCacheEntry");
const getCacheEntry_1 = require("./getCacheEntry");
/** base node used to remember references when a globalKey is set */
var _baseEntry = {};
const _baseEntry = {};
/**

@@ -15,3 +15,3 @@ * Primary functional worker used to implement the caching pattern

function getMemoValueWorker(entry, factory, keys) {
var foundEntry = (0, getCacheEntry_1.getCacheEntry)(entry, keys);
const foundEntry = (0, getCacheEntry_1.getCacheEntry)(entry, keys);
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory

@@ -21,3 +21,3 @@ if (!foundEntry.hasOwnProperty('value')) {

}
return [foundEntry.value, function (fact, args) { return getMemoValueWorker(foundEntry, fact, args); }];
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
}

@@ -32,6 +32,6 @@ /**

function getMemoCache(globalKey) {
var entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
return function (fact, args) { return getMemoValueWorker(entry, fact, args); };
const entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
return (fact, args) => getMemoValueWorker(entry, fact, args);
}
exports.getMemoCache = getMemoCache;
//# sourceMappingURL=getMemoCache.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var getMemoCache_1 = require("./getMemoCache");
const getMemoCache_1 = require("./getMemoCache");
function getObjFactory() {
var obj = { id: 0 };
return function () { return ({
const obj = { id: 0 };
return () => ({
id: obj.id++,
}); };
});
}
describe('getMemoCache unit tests', function () {
test('memoValue with null function', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var val = memoValue(null, ['foo', 'bar'])[0];
describe('getMemoCache unit tests', () => {
test('memoValue with null function', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const [val] = memoValue(null, ['foo', 'bar']);
expect(val).toBeNull();
});
test('memoValue with undefined', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var val = memoValue(undefined, ['foo', 'bar'])[0];
test('memoValue with undefined', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const [val] = memoValue(undefined, ['foo', 'bar']);
expect(val).toBeUndefined();
});
test('memoValue with string', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var val = memoValue('foo', ['bar', 'baz'])[0];
test('memoValue with string', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const [val] = memoValue('foo', ['bar', 'baz']);
expect(val).toEqual('foo');
});
test('memoValue with object', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var obj = { foo: 'hello', bar: 2, baz: 'you' };
var val = memoValue(obj, ['hello', obj])[0];
test('memoValue with object', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const obj = { foo: 'hello', bar: 2, baz: 'you' };
const [val] = memoValue(obj, ['hello', obj]);
expect(val).toBe(obj);
});
test('memoValue executes function', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var fn = getObjFactory();
var v1 = fn();
var v2 = memoValue(fn, ['bar', 'baz'])[0];
test('memoValue executes function', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const fn = getObjFactory();
const v1 = fn();
const [v2] = memoValue(fn, ['bar', 'baz']);
expect(v1).not.toBe(v2);
expect(v1.id).not.toEqual(v2.id);
});
test('memo calls function only once', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var fn = getObjFactory();
var keys = ['hello', 'world'];
var o1 = memoValue(fn, keys)[0];
var o2 = memoValue(fn, keys)[0];
test('memo calls function only once', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const fn = getObjFactory();
const keys = ['hello', 'world'];
const [o1] = memoValue(fn, keys);
const [o2] = memoValue(fn, keys);
expect(o2).toBe(o1);
});
test('memo calls function only once for empty inputs', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var fn = getObjFactory();
var o1 = memoValue(fn, undefined)[0];
var o2 = memoValue(fn, undefined)[0];
test('memo calls function only once for empty inputs', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const fn = getObjFactory();
const [o1] = memoValue(fn, undefined);
const [o2] = memoValue(fn, undefined);
expect(o2).toBe(o1);
});
test('sub caches are separate', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var base1 = {};
var base2 = {};
var _a = memoValue(null, [base1]), getCache1 = _a[1];
var _b = memoValue(null, [base2]), getCache2 = _b[1];
var objKey = {};
var fn = getObjFactory();
var o1 = getCache1(fn, [objKey])[0];
var o2 = getCache2(fn, [objKey])[0];
var o3 = getCache2(fn, [objKey])[0];
test('sub caches are separate', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const base1 = {};
const base2 = {};
const [, getCache1] = memoValue(null, [base1]);
const [, getCache2] = memoValue(null, [base2]);
const objKey = {};
const fn = getObjFactory();
const [o1] = getCache1(fn, [objKey]);
const [o2] = getCache2(fn, [objKey]);
const [o3] = getCache2(fn, [objKey]);
expect(o1).not.toBe(o2);
expect(o3).toBe(o2);
});
test('sub caches work on branches', function () {
var memoValue = (0, getMemoCache_1.getMemoCache)();
var keys1 = [{}, 2, 'hello'];
var keys2 = [{}, true];
var fn = getObjFactory();
var _a = memoValue(null, keys1), getMemoValue = _a[1];
var val1 = getMemoValue(fn, keys2)[0];
var val2 = memoValue(fn, tslib_1.__spreadArray(tslib_1.__spreadArray([], keys1, true), keys2, true))[0];
test('sub caches work on branches', () => {
const memoValue = (0, getMemoCache_1.getMemoCache)();
const keys1 = [{}, 2, 'hello'];
const keys2 = [{}, true];
const fn = getObjFactory();
const [, getMemoValue] = memoValue(null, keys1);
const [val1] = getMemoValue(fn, keys2);
const [val2] = memoValue(fn, [...keys1, ...keys2]);
expect(val2).toBe(val1);

@@ -79,0 +78,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoize = void 0;
var getMemoCache_1 = require("./getMemoCache");
const getMemoCache_1 = require("./getMemoCache");
/**

@@ -12,10 +12,6 @@ * This wraps a function to memoize the results using the standard javascript memoization pattern

// create a unique cache that will be captured in the closure
var cache = (0, getMemoCache_1.getMemoCache)();
const cache = (0, getMemoCache_1.getMemoCache)();
// create the closure which wraps the calling function
var closure = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return cache(function () { return fn.apply(void 0, (args || [])); }, args)[0];
const closure = (...args) => {
return cache(() => fn(...(args || [])), args)[0];
};

@@ -22,0 +18,0 @@ // now return that closure strongly typed as the function.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var memoize_1 = require("./memoize");
var _globalCalls = 0;
describe('Memoize unit tests', function () {
test('simple function no args', function () {
var noArgsFn = (0, memoize_1.memoize)(function () {
const memoize_1 = require("./memoize");
let _globalCalls = 0;
describe('Memoize unit tests', () => {
test('simple function no args', () => {
const noArgsFn = (0, memoize_1.memoize)(() => {
return ++_globalCalls;
});
var result1 = noArgsFn();
const result1 = noArgsFn();
expect(noArgsFn()).toEqual(result1);
});
test('simple function 1 arg', function () {
var incrementFn = (0, memoize_1.memoize)(function (bump) {
test('simple function 1 arg', () => {
const incrementFn = (0, memoize_1.memoize)((bump) => {
++_globalCalls;

@@ -19,3 +19,3 @@ return bump + 1;

expect(incrementFn(3)).toEqual(4);
var calls = _globalCalls;
const calls = _globalCalls;
incrementFn(3);

@@ -28,4 +28,4 @@ expect(_globalCalls).toEqual(calls);

});
test('void function 2 args', function () {
var voidFn = (0, memoize_1.memoize)(function (a, b) {
test('void function 2 args', () => {
const voidFn = (0, memoize_1.memoize)((a, b) => {
if (a) {

@@ -42,3 +42,3 @@ ++_globalCalls;

voidFn(3, 'hello');
var calls = _globalCalls;
const calls = _globalCalls;
voidFn(3, 'hello');

@@ -45,0 +45,0 @@ expect(_globalCalls).toEqual(calls);

@@ -28,8 +28,8 @@ /**

// eslint-disable-next-line @typescript-eslint/ban-types
var byObj = (entry.obj = entry.obj || new WeakMap());
const byObj = (entry.obj = entry.obj || new WeakMap());
return byObj.get(val) || byObj.set(val, {}).get(val);
}
// otherwise convert everything to a string and store it in the str object (using it as a map)
var key = val + '';
var byString = ensureAndReturn(entry, 'str');
const key = val + '';
const byString = ensureAndReturn(entry, 'str');
return (byString[key] = byString[key] || {});

@@ -48,5 +48,5 @@ }

return args && args.length > 0
? args.reduce(function (previous, arg) { return jumpToCacheEntry(previous, arg); }, entry)
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
: ensureAndReturn(entry, 'noargs');
}
//# sourceMappingURL=getCacheEntry.js.map

@@ -1,5 +0,4 @@

import { __spreadArray } from "tslib";
import { getCacheEntry } from './getCacheEntry';
function compareResults(base, args, argsNoMatch) {
var e1 = getCacheEntry(base, args);
const e1 = getCacheEntry(base, args);
expect(getCacheEntry(base, args)).toBe(e1);

@@ -10,50 +9,50 @@ if (argsNoMatch) {

}
describe('Memo cache unit tests', function () {
test('undefined args to return noargs', function () {
var base = {};
describe('Memo cache unit tests', () => {
test('undefined args to return noargs', () => {
const base = {};
expect(getCacheEntry(base, undefined)).toBe(base.noargs);
});
test('empty args array to return noargs entry', function () {
var base = {};
test('empty args array to return noargs entry', () => {
const base = {};
expect(getCacheEntry(base, [])).toBe(base.noargs);
});
test('undefined goes to empty entry', function () {
var base = {};
test('undefined goes to empty entry', () => {
const base = {};
expect(getCacheEntry(base, [undefined])).toBe(base.empty);
});
test('null to go to empty entry', function () {
var base = {};
test('null to go to empty entry', () => {
const base = {};
expect(getCacheEntry(base, [null])).toBe(base.empty);
});
test('string gets keyed correctly', function () {
var base = {};
var key = 'foo';
test('string gets keyed correctly', () => {
const base = {};
const key = 'foo';
expect(getCacheEntry(base, [key])).toBe(base.str[key]);
});
test('number gets keyed correctly', function () {
var base = {};
var val = 235;
var key = val + '';
test('number gets keyed correctly', () => {
const base = {};
const val = 235;
const key = val + '';
expect(getCacheEntry(base, [val])).toBe(base.str[key]);
});
test('bool gets keyed correctly', function () {
var base = {};
var val = true;
var key = val + '';
test('bool gets keyed correctly', () => {
const base = {};
const val = true;
const key = val + '';
expect(getCacheEntry(base, [val])).toBe(base.str[key]);
});
test('false bool gets keyed correctly', function () {
var base = {};
var val = false;
var key = val + '';
test('false bool gets keyed correctly', () => {
const base = {};
const val = false;
const key = val + '';
expect(getCacheEntry(base, [val])).toBe(base.str[key]);
});
test('object gets keyed correctly', function () {
var base = {};
var key = {};
test('object gets keyed correctly', () => {
const base = {};
const key = {};
expect(getCacheEntry(base, [key])).toBe(base.obj.get(key));
});
test('function gets keyed correctly', function () {
var base = {};
var key = function () {
test('function gets keyed correctly', () => {
const base = {};
const key = () => {
return 'hello world';

@@ -63,36 +62,36 @@ };

});
test('basic string retrieval', function () {
test('basic string retrieval', () => {
compareResults({}, ['hello', 'world'], ['hello world']);
});
test('mixed keys with strings', function () {
test('mixed keys with strings', () => {
compareResults({}, ['hello', 1, true, undefined, 'world'], ['hello', 1, true, '', 'world']);
});
test('basic object matches', function () {
var obj = {};
test('basic object matches', () => {
const obj = {};
compareResults({}, [obj]);
});
test('mixed object and string matches', function () {
var obj = {};
test('mixed object and string matches', () => {
const obj = {};
compareResults({}, [obj, 'hello', 1, 'world']);
});
test('mixed obj and strings with obj at end', function () {
var obj = {};
var obj2 = {};
test('mixed obj and strings with obj at end', () => {
const obj = {};
const obj2 = {};
compareResults({}, ['hello', 1, 'world', obj], ['hello', 1, 'world', obj2]);
});
test('hybrid sets', function () {
var obj = {};
var obj2 = {};
test('hybrid sets', () => {
const obj = {};
const obj2 = {};
compareResults({}, ['hello', obj, 'world', 1, false, obj2, undefined]);
});
test('sub cache on object', function () {
var obj = {};
var args1 = ['hello', obj];
var base = {};
var subRoot = getCacheEntry(base, args1);
var args2 = ['world', base];
var target = getCacheEntry(subRoot, args2);
expect(getCacheEntry(base, __spreadArray(__spreadArray([], args1, true), args2, true))).toBe(target);
test('sub cache on object', () => {
const obj = {};
const args1 = ['hello', obj];
const base = {};
const subRoot = getCacheEntry(base, args1);
const args2 = ['world', base];
const target = getCacheEntry(subRoot, args2);
expect(getCacheEntry(base, [...args1, ...args2])).toBe(target);
});
});
//# sourceMappingURL=getCacheEntry.test.js.map
import { getCacheEntry } from './getCacheEntry';
/** base node used to remember references when a globalKey is set */
var _baseEntry = {};
const _baseEntry = {};
/**

@@ -12,3 +12,3 @@ * Primary functional worker used to implement the caching pattern

function getMemoValueWorker(entry, factory, keys) {
var foundEntry = getCacheEntry(entry, keys);
const foundEntry = getCacheEntry(entry, keys);
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory

@@ -18,3 +18,3 @@ if (!foundEntry.hasOwnProperty('value')) {

}
return [foundEntry.value, function (fact, args) { return getMemoValueWorker(foundEntry, fact, args); }];
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
}

@@ -29,5 +29,5 @@ /**

export function getMemoCache(globalKey) {
var entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
return function (fact, args) { return getMemoValueWorker(entry, fact, args); };
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
return (fact, args) => getMemoValueWorker(entry, fact, args);
}
//# sourceMappingURL=getMemoCache.js.map

@@ -1,76 +0,75 @@

import { __spreadArray } from "tslib";
import { getMemoCache } from './getMemoCache';
function getObjFactory() {
var obj = { id: 0 };
return function () { return ({
const obj = { id: 0 };
return () => ({
id: obj.id++,
}); };
});
}
describe('getMemoCache unit tests', function () {
test('memoValue with null function', function () {
var memoValue = getMemoCache();
var val = memoValue(null, ['foo', 'bar'])[0];
describe('getMemoCache unit tests', () => {
test('memoValue with null function', () => {
const memoValue = getMemoCache();
const [val] = memoValue(null, ['foo', 'bar']);
expect(val).toBeNull();
});
test('memoValue with undefined', function () {
var memoValue = getMemoCache();
var val = memoValue(undefined, ['foo', 'bar'])[0];
test('memoValue with undefined', () => {
const memoValue = getMemoCache();
const [val] = memoValue(undefined, ['foo', 'bar']);
expect(val).toBeUndefined();
});
test('memoValue with string', function () {
var memoValue = getMemoCache();
var val = memoValue('foo', ['bar', 'baz'])[0];
test('memoValue with string', () => {
const memoValue = getMemoCache();
const [val] = memoValue('foo', ['bar', 'baz']);
expect(val).toEqual('foo');
});
test('memoValue with object', function () {
var memoValue = getMemoCache();
var obj = { foo: 'hello', bar: 2, baz: 'you' };
var val = memoValue(obj, ['hello', obj])[0];
test('memoValue with object', () => {
const memoValue = getMemoCache();
const obj = { foo: 'hello', bar: 2, baz: 'you' };
const [val] = memoValue(obj, ['hello', obj]);
expect(val).toBe(obj);
});
test('memoValue executes function', function () {
var memoValue = getMemoCache();
var fn = getObjFactory();
var v1 = fn();
var v2 = memoValue(fn, ['bar', 'baz'])[0];
test('memoValue executes function', () => {
const memoValue = getMemoCache();
const fn = getObjFactory();
const v1 = fn();
const [v2] = memoValue(fn, ['bar', 'baz']);
expect(v1).not.toBe(v2);
expect(v1.id).not.toEqual(v2.id);
});
test('memo calls function only once', function () {
var memoValue = getMemoCache();
var fn = getObjFactory();
var keys = ['hello', 'world'];
var o1 = memoValue(fn, keys)[0];
var o2 = memoValue(fn, keys)[0];
test('memo calls function only once', () => {
const memoValue = getMemoCache();
const fn = getObjFactory();
const keys = ['hello', 'world'];
const [o1] = memoValue(fn, keys);
const [o2] = memoValue(fn, keys);
expect(o2).toBe(o1);
});
test('memo calls function only once for empty inputs', function () {
var memoValue = getMemoCache();
var fn = getObjFactory();
var o1 = memoValue(fn, undefined)[0];
var o2 = memoValue(fn, undefined)[0];
test('memo calls function only once for empty inputs', () => {
const memoValue = getMemoCache();
const fn = getObjFactory();
const [o1] = memoValue(fn, undefined);
const [o2] = memoValue(fn, undefined);
expect(o2).toBe(o1);
});
test('sub caches are separate', function () {
var memoValue = getMemoCache();
var base1 = {};
var base2 = {};
var _a = memoValue(null, [base1]), getCache1 = _a[1];
var _b = memoValue(null, [base2]), getCache2 = _b[1];
var objKey = {};
var fn = getObjFactory();
var o1 = getCache1(fn, [objKey])[0];
var o2 = getCache2(fn, [objKey])[0];
var o3 = getCache2(fn, [objKey])[0];
test('sub caches are separate', () => {
const memoValue = getMemoCache();
const base1 = {};
const base2 = {};
const [, getCache1] = memoValue(null, [base1]);
const [, getCache2] = memoValue(null, [base2]);
const objKey = {};
const fn = getObjFactory();
const [o1] = getCache1(fn, [objKey]);
const [o2] = getCache2(fn, [objKey]);
const [o3] = getCache2(fn, [objKey]);
expect(o1).not.toBe(o2);
expect(o3).toBe(o2);
});
test('sub caches work on branches', function () {
var memoValue = getMemoCache();
var keys1 = [{}, 2, 'hello'];
var keys2 = [{}, true];
var fn = getObjFactory();
var _a = memoValue(null, keys1), getMemoValue = _a[1];
var val1 = getMemoValue(fn, keys2)[0];
var val2 = memoValue(fn, __spreadArray(__spreadArray([], keys1, true), keys2, true))[0];
test('sub caches work on branches', () => {
const memoValue = getMemoCache();
const keys1 = [{}, 2, 'hello'];
const keys2 = [{}, true];
const fn = getObjFactory();
const [, getMemoValue] = memoValue(null, keys1);
const [val1] = getMemoValue(fn, keys2);
const [val2] = memoValue(fn, [...keys1, ...keys2]);
expect(val2).toBe(val1);

@@ -77,0 +76,0 @@ });

@@ -9,10 +9,6 @@ import { getMemoCache } from './getMemoCache';

// create a unique cache that will be captured in the closure
var cache = getMemoCache();
const cache = getMemoCache();
// create the closure which wraps the calling function
var closure = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return cache(function () { return fn.apply(void 0, (args || [])); }, args)[0];
const closure = (...args) => {
return cache(() => fn(...(args || [])), args)[0];
};

@@ -19,0 +15,0 @@ // now return that closure strongly typed as the function.

import { memoize } from './memoize';
var _globalCalls = 0;
describe('Memoize unit tests', function () {
test('simple function no args', function () {
var noArgsFn = memoize(function () {
let _globalCalls = 0;
describe('Memoize unit tests', () => {
test('simple function no args', () => {
const noArgsFn = memoize(() => {
return ++_globalCalls;
});
var result1 = noArgsFn();
const result1 = noArgsFn();
expect(noArgsFn()).toEqual(result1);
});
test('simple function 1 arg', function () {
var incrementFn = memoize(function (bump) {
test('simple function 1 arg', () => {
const incrementFn = memoize((bump) => {
++_globalCalls;

@@ -17,3 +17,3 @@ return bump + 1;

expect(incrementFn(3)).toEqual(4);
var calls = _globalCalls;
const calls = _globalCalls;
incrementFn(3);

@@ -26,4 +26,4 @@ expect(_globalCalls).toEqual(calls);

});
test('void function 2 args', function () {
var voidFn = memoize(function (a, b) {
test('void function 2 args', () => {
const voidFn = memoize((a, b) => {
if (a) {

@@ -40,3 +40,3 @@ ++_globalCalls;

voidFn(3, 'hello');
var calls = _globalCalls;
const calls = _globalCalls;
voidFn(3, 'hello');

@@ -43,0 +43,0 @@ expect(_globalCalls).toEqual(calls);

{
"name": "@fluentui-react-native/memo-cache",
"version": "1.3.3",
"version": "1.3.4",
"description": "Layered memoization style cache helper",

@@ -12,2 +12,9 @@ "repository": {

"module": "lib/index.js",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib-commonjs/index.js",
"types": "./lib/index.d.ts"
}
},
"typings": "lib/index.d.ts",

@@ -14,0 +21,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet