Working on webview persistence API

#49022
This commit is contained in:
Matt Bierner
2018-05-14 10:34:44 -07:00
parent 704268958b
commit 21ee81c03b
13 changed files with 68 additions and 96 deletions

View File

@@ -15,18 +15,26 @@ export interface PreviewSettings {
let cachedSettings: PreviewSettings | undefined = undefined;
export function getData(key: string): PreviewSettings {
const element = document.getElementById('vscode-markdown-preview-data');
if (element) {
const data = element.getAttribute(key);
if (data) {
return JSON.parse(data);
}
}
throw new Error(`Could not load data for ${key}`);
}
export function getSettings(): PreviewSettings {
if (cachedSettings) {
return cachedSettings;
}
const element = document.getElementById('vscode-markdown-preview-data');
if (element) {
const data = element.getAttribute('data-settings');
if (data) {
cachedSettings = JSON.parse(data);
return cachedSettings!;
}
cachedSettings = getData('data-settings');
if (cachedSettings) {
return cachedSettings;
}
throw new Error('Could not load settings');