Skip to content

Commit

Permalink
add getKey and forgetKey API's to optimism
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofian Hnaide committed Apr 21, 2021
1 parent be42d88 commit 9e20661
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"jest-fetch-mock": "^3.0.3",
"jest-junit": "12.0.0",
"lodash": "4.17.21",
"patch-package": "6.4.7",
"react": "17.0.1",
"react-dom": "17.0.1",
"recast": "0.20.4",
Expand Down
47 changes: 47 additions & 0 deletions patches/optimism+0.15.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git a/node_modules/optimism/lib/bundle.cjs.js b/node_modules/optimism/lib/bundle.cjs.js
index 26e4f9e..eaf15bf 100644
--- a/node_modules/optimism/lib/bundle.cjs.js
+++ b/node_modules/optimism/lib/bundle.cjs.js
@@ -458,6 +458,12 @@ function wrap(originalFunction, options) {
var key = makeCacheKey.apply(null, arguments);
return key !== void 0 && cache.delete(key);
};
+ optimistic.getKey = function () {
+ return makeCacheKey.apply(null, keyArgs ? keyArgs.apply(null, arguments) : arguments);
+ };
+ optimistic.forgetKey = function (key) {
+ return key !== void 0 && cache.delete(key);
+ };
return optimistic;
}

diff --git a/node_modules/optimism/lib/bundle.esm.js b/node_modules/optimism/lib/bundle.esm.js
index 02bc3e5..05e30fc 100644
--- a/node_modules/optimism/lib/bundle.esm.js
+++ b/node_modules/optimism/lib/bundle.esm.js
@@ -456,6 +456,12 @@ function wrap(originalFunction, options) {
var key = makeCacheKey.apply(null, arguments);
return key !== void 0 && cache.delete(key);
};
+ optimistic.getKey = function () {
+ return makeCacheKey.apply(null, keyArgs ? keyArgs.apply(null, arguments) : arguments);
+ };
+ optimistic.forgetKey = function (key) {
+ return key !== void 0 && cache.delete(key);
+ };
return optimistic;
}

diff --git a/node_modules/optimism/lib/index.d.ts b/node_modules/optimism/lib/index.d.ts
index e945216..5676430 100644
--- a/node_modules/optimism/lib/index.d.ts
+++ b/node_modules/optimism/lib/index.d.ts
@@ -8,6 +8,8 @@ export declare type OptimisticWrapperFunction<TArgs extends any[], TResult, TKey
dirty: (...args: TKeyArgs) => void;
peek: (...args: TKeyArgs) => TResult | undefined;
forget: (...args: TKeyArgs) => boolean;
+ getKey: (...args: TArgs) => any;
+ forgetKey: (key: any) => boolean;
};
export declare type OptimisticWrapOptions<TArgs extends any[], TKeyArgs extends any[] = TArgs> = {
max?: number;

0 comments on commit 9e20661

Please sign in to comment.