@neovici/cosmoz-utils 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/memoize.d.ts +1 -0
- package/dist/memoize.js +14 -3
- package/package.json +1 -1
package/dist/memoize.d.ts
CHANGED
package/dist/memoize.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const memize = (fn) => {
|
|
2
|
+
let called = false, lastResult;
|
|
3
|
+
return function () {
|
|
4
|
+
if (called) {
|
|
5
|
+
return lastResult;
|
|
6
|
+
}
|
|
7
|
+
const result = fn();
|
|
8
|
+
lastResult = result;
|
|
9
|
+
called = true;
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
}, memoize = (fn) => {
|
|
2
13
|
let lastArg, lastResult;
|
|
3
14
|
return function (arg) {
|
|
4
15
|
if (lastArg === arg) {
|
|
@@ -9,7 +20,7 @@ export const memoize = fn => {
|
|
|
9
20
|
lastArg = arg;
|
|
10
21
|
return result;
|
|
11
22
|
};
|
|
12
|
-
}, memooize = fn => {
|
|
23
|
+
}, memooize = (fn) => {
|
|
13
24
|
let lastArg1, lastArg2, lastResult;
|
|
14
25
|
return function (arg1, arg2) {
|
|
15
26
|
if (lastArg1 === arg1 && lastArg2 === arg2) {
|
|
@@ -21,7 +32,7 @@ export const memoize = fn => {
|
|
|
21
32
|
lastArg2 = arg2;
|
|
22
33
|
return result;
|
|
23
34
|
};
|
|
24
|
-
}, memoooize = fn => {
|
|
35
|
+
}, memoooize = (fn) => {
|
|
25
36
|
let lastArg1, lastArg2, lastArg3, lastResult;
|
|
26
37
|
return function (arg1, arg2, arg3) {
|
|
27
38
|
if (lastArg1 === arg1 && lastArg2 === arg2 && lastArg3 === arg3) {
|