• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ringcentral / ringcentral-js-widgets / 21017357600

15 Jan 2026 02:19AM UTC coverage: 61.994% (-1.1%) from 63.06%
21017357600

push

github

web-flow
misc: sync features and bugfixes from 8f9fbb5dfe (#1784)

* misc: sync crius

* chore: update babel-setting deps

* feat(core): update logger and add fromWatch

* misc: fix tsconfig

* misc: fix tsconfig

* misc: update eslint-settings and new eslint-plugin-crius package

* chore: remove ci and nx from package.json

* feat(i18n): new getAcceptLocaleMap and preudo string support

* chore: add preudo i18n

* misc(locale-loader): convert to ts, new format support

* misc(locale-settings): use ts

* chore: add format test in phone number lib

* feat(react-hooks): add more hooks

* chore: add comments

* misc: add more mock files

* misc: update test utils

* misc: update utils

* chore: update tsconfig

* misc: update i18n string, and convert to ts

* feat: update ui components, support emoji input, new video setting ui

* feat: new rcvideo v2 module

* feat: use new subscription register api

* misc(commons): update enums/interfaces

* misc: update Analytics lib

* misc: upgrade uuid and update import

* misc(commons): update formatDuration lib

* misc(test): add test steps

* chore: update tests and more feature tests

* misc: update demo project

* misc: update cli template

* misc: fix deps issue

* misc: remove glip widgets package

* misc: fix wrong import path

* misc: limit jest worker memory

* chore: use npm trusted-publishers

10285 of 18150 branches covered (56.67%)

Branch coverage included in aggregate %.

986 of 2186 new or added lines in 228 files covered. (45.11%)

44 existing lines in 23 files now uncovered.

17404 of 26514 relevant lines covered (65.64%)

167640.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/packages/utils/src/utils/createWithMemorizeByKey.ts
1
import memoize from 'lodash/memoize';
2

3
/**
4
 * use lodash memoize to cache the result of cb exec result
5
 * and shared the promise with the same `cache key`
6
 */
7
export const createWithMemorizeByKey = <T = string | null>() => {
305✔
8
  const withMemorizeByKey = memoize(
1✔
9
    (cb: () => Promise<T>, _cacheKey: string) => cb(),
1✔
10
    (_, cacheKey) => cacheKey,
2✔
11
  );
12

13
  const toWithMemorizeByKey = withMemorizeByKey as typeof withMemorizeByKey & {
1✔
14
    /**
15
     *
16
     * @returns clear cached state and promise
17
     */
18
    clear: (
19
      cb?: (
20
        /**
21
         * cached data callback before clear
22
         */
23
        data: T,
24
      ) => void,
25
    ) => void;
26
    /**
27
     * get the full cached map data
28
     */
29
    get value(): Record<string, T>;
30
  };
31

32
  Object.defineProperty(withMemorizeByKey, 'value', {
1✔
NEW
33
    get: () => (withMemorizeByKey.cache as any)?.__data__?.string?.__data__,
×
34
  });
35

36
  Object.defineProperty(withMemorizeByKey, 'clear', {
1✔
37
    writable: false,
38
    value: async (
39
      cb: (
40
        /**
41
         * cached data callback before clear
42
         */
43
        data: T,
44
      ) => void,
45
    ) => {
NEW
46
      const cachedMap = toWithMemorizeByKey.value;
×
47

NEW
48
      for (const cache of Object.values(cachedMap)) {
×
NEW
49
        const value = await cache;
×
50

NEW
51
        cb?.(value);
×
52
      }
53

NEW
54
      withMemorizeByKey.cache.clear?.();
×
55
    },
56
  });
57

58
  return toWithMemorizeByKey;
1✔
59
};
60

61
/**
62
 * save the result of promise to local cache by cacheKey, and can get the result by cacheKey in sync way
63
 *
64
 * ```ts
65
 * const withLocalCache = createWithLocalCache<string>();
66
 *
67
 * const fetchData = async () => {
68
 *   // Simulate an async operation
69
 *   return new Promise<string>((resolve) => {
70
 *     setTimeout(() => resolve('data'), 1000);
71
 *   });
72
 * };
73
 *
74
 * const withLocalCache = createWithLocalCache<string>();
75
 *   const cacheKey = 'uniqueKey';
76
 *
77
 *   // Fetch data and cache it
78
 *   const data = await withLocalCache(fetchData(), cacheKey);
79
 *   console.log(data); // Output: 'data'
80
 *
81
 *   // Retrieve cached data synchronously
82
 *   const cachedData = withLocalCache.get(cacheKey);
83
 *   console.log(cachedData); // Output: 'data'
84
 *
85
 *   // Clear the cache
86
 *   withLocalCache.clear();
87
 *   const clearedData = withLocalCache.get(cacheKey);
88
 *   console.log(clearedData); // Output: undefined
89
 * ```
90
 */
91
export const createWithLocalCache = <T = string | null>() => {
305✔
92
  const localCache = new Map<string, T>();
2✔
93

94
  const withLocalCache = async (promise: Promise<T>, _cacheKey: string) => {
2✔
95
    const result = await promise;
2✔
96
    localCache.set(_cacheKey, result);
2✔
97
    return result;
2✔
98
  };
99

100
  Object.defineProperty(withLocalCache, 'clear', {
2✔
101
    writable: false,
102
    value: () => localCache.clear(),
1✔
103
  });
104

105
  Object.defineProperty(withLocalCache, 'get', {
2✔
106
    writable: false,
107
    value: (cacheKey: string) => localCache.get(cacheKey),
2✔
108
  });
109

110
  Object.defineProperty(withLocalCache, 'value', {
2✔
NEW
111
    get: () => localCache,
×
112
  });
113

114
  return withLocalCache as typeof withLocalCache & {
2✔
115
    /**
116
     *
117
     * @returns clear local cached state
118
     */
119
    clear: () => void;
120
    /**
121
     * get the cached result by cacheKey in sync way
122
     * @param cacheKey
123
     */
124
    get: (cacheKey: string) => T | undefined;
125
    /**
126
     * get the full cached map data
127
     */
128
    get value(): Map<string, T>;
129
  };
130
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc