/**
 * What each screen last loaded, kept in memory while this wp-admin page is
 * open, so going back to a screen shows it at once instead of loading it
 * again. Nothing is written anywhere: a page reload starts empty.
 *
 * Emptied when the data may have changed: after a save (api.ts) and after a
 * sync (sync.ts). Screens that are open then reload themselves.
 */

const entries = new Map< string, unknown >();

export function cachedScreen< T >( key: string ): T | undefined {
	return entries.get( key ) as T | undefined;
}

export function cacheScreen( key: string, value: unknown ): void {
	entries.set( key, value );
}

export function forgetScreens(): void {
	entries.clear();
}
