* Views when disposed can cache their state to be restored when opened again. * The short cache is cleared after 3 seconds of inactivity. * The long cache is cleared when the view is opened again.
()
| 70 | * The long cache is cleared when the view is opened again. |
| 71 | */ |
| 72 | function createViewCache() { |
| 73 | type CacheDataMap = { |
| 74 | [debug.DevtoolsMainView.Structure]: structure.Cache |
| 75 | } |
| 76 | let shortCache: null | any = null |
| 77 | let nextShortCache: typeof shortCache = null |
| 78 | const longCache = new Map<keyof CacheDataMap, any>() |
| 79 | |
| 80 | const clearShortCache = debounce(() => { |
| 81 | shortCache = null |
| 82 | nextShortCache = null |
| 83 | }, 3 * SECOND) |
| 84 | |
| 85 | function setCacheGetter<T extends debug.DevtoolsMainView>(view: T, getter: () => CacheDataMap[T]) { |
| 86 | s.onCleanup(() => { |
| 87 | const data = getter() |
| 88 | nextShortCache = {view: view as any, data: data.short} |
| 89 | longCache.set(view, data.long) |
| 90 | clearShortCache() |
| 91 | }) |
| 92 | } |
| 93 | function getCache<T extends debug.DevtoolsMainView>( |
| 94 | view: T, |
| 95 | ): {[K in 'short' | 'long']: CacheDataMap[T][K] | null} { |
| 96 | const short = shortCache && shortCache.view === view ? shortCache.data : null |
| 97 | shortCache = nextShortCache |
| 98 | nextShortCache = null |
| 99 | const long = longCache.get(view) |
| 100 | longCache.delete(view) |
| 101 | return {short, long} |
| 102 | } |
| 103 | |
| 104 | return {set: setCacheGetter, get: getCache} |
| 105 | } |
| 106 | |
| 107 | function createAppCtx(props: DevtoolsOptions) { |
| 108 |
no outgoing calls
no test coverage detected
searching dependent graphs…