From 31345b5af922c3093e38ab20a90c6dce61560043 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 5 Oct 2019 23:29:14 -0400 Subject: [PATCH] workflow(template-explorer): persist compilerOptions --- packages/template-explorer/src/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/template-explorer/src/index.ts b/packages/template-explorer/src/index.ts index 89c33f99be..22199eaa03 100644 --- a/packages/template-explorer/src/index.ts +++ b/packages/template-explorer/src/index.ts @@ -8,9 +8,11 @@ const self = window as any self.init = () => { const monaco = (window as any).monaco as typeof m - const persistedContent = - decodeURIComponent(window.location.hash.slice(1)) || - `
{{ foo + bar }}
` + const persistedState = JSON.parse( + decodeURIComponent(window.location.hash.slice(1)) || `{}` + ) + + Object.assign(compilerOptions, persistedState.options) let lastSuccessfulCode: string = `/* See console for error */` let lastSuccessfulMap: SourceMapConsumer | undefined = undefined @@ -56,7 +58,13 @@ self.init = () => { function reCompile() { const src = editor.getValue() - window.location.hash = encodeURIComponent(src) + // every time we re-compile, persist current state to URL + window.location.hash = encodeURIComponent( + JSON.stringify({ + src, + options: compilerOptions + }) + ) const res = compileCode(src) if (res) { output.setValue(res) @@ -78,7 +86,7 @@ self.init = () => { const editor = monaco.editor.create( document.getElementById('source') as HTMLElement, { - value: persistedContent, + value: persistedState.src || `
Hello World!
`, language: 'html', ...sharedEditorOptions } -- 2.47.3