66import { defineComponent } from 'vue'
77import { WebviewApi } from 'vscode-webview'
88import { AwsSamDebuggerConfiguration } from '../../shared/sam/debugger/awsSamDebugConfiguration'
9- import { AwsSamDebuggerConfigurationLoose , SamInvokerResponse , SamInvokeVueState } from './samInvokeBackend'
9+ import { AwsSamDebuggerConfigurationLoose , SamInvokerResponse } from './samInvokeBackend'
1010import settingsPanel from '../../webviews/components/settingsPanel.vue'
1111
12- declare const vscode : WebviewApi < SamInvokeVueState >
12+ declare const vscode : WebviewApi < SamInvokeVueData >
1313
1414interface VueDataLaunchPropertyObject {
1515 value : string
@@ -94,9 +94,12 @@ export default defineComponent({
9494 settingsPanel,
9595 } ,
9696 created ( ) {
97- const oldState : Partial < SamInvokeVueState > = vscode . getState ( ) ?? { }
98- this . launchConfig = oldState . launchConfig ?? this . launchConfig
99- this . payload = oldState . payload ?? this . payload
97+ const oldState : Partial < SamInvokeVueData > = vscode . getState ( ) ?? { }
98+
99+ const keys = Object . keys ( oldState ) as [ keyof SamInvokeVueData ]
100+ keys . forEach ( k => {
101+ this . $data [ k ] = oldState [ k ] ?? this . $data [ k ]
102+ } )
100103
101104 window . addEventListener ( 'message' , ev => {
102105 const event = ev . data as SamInvokerResponse
@@ -113,7 +116,7 @@ export default defineComponent({
113116 this . launchConfig . invokeTarget . templatePath = event . data . template
114117 break
115118 case 'loadSamLaunchConfig' :
116- if ( oldState . launchConfig !== undefined ) {
119+ if ( oldState . launchConfig !== undefined && event . data . initialCall ) {
117120 return
118121 }
119122
@@ -143,6 +146,19 @@ export default defineComponent({
143146 }
144147 } )
145148
149+ Object . keys ( this . $data ) . forEach ( k => {
150+ this . $watch (
151+ k ,
152+ ( v : any ) => {
153+ const old = vscode . getState ( )
154+ vscode . setState (
155+ Object . assign ( old ?? { } , { [ k ] : JSON . parse ( JSON . stringify ( v ) ) } ) as SamInvokeVueData
156+ )
157+ } ,
158+ { deep : true }
159+ )
160+ } )
161+
146162 // Send a message back to let the backend know we're ready for messages
147163 vscode . postMessage ( { command : 'initialized' } )
148164 } ,
@@ -167,28 +183,6 @@ export default defineComponent({
167183 stageVariables : { value : '' , errorMsg : '' } ,
168184 }
169185 } ,
170- watch : {
171- launchConfig : {
172- handler ( newval : AwsSamDebuggerConfigurationLoose ) {
173- vscode . setState (
174- Object . assign ( vscode . getState ( ) ?? { } , {
175- launchConfig : JSON . parse ( JSON . stringify ( newval ) ) ,
176- } as SamInvokeVueState )
177- )
178- } ,
179- deep : true ,
180- } ,
181- payload : {
182- handler ( newval : { value : string ; errorMsg : string } ) {
183- vscode . setState (
184- Object . assign ( vscode . getState ( ) ?? { } , {
185- payload : JSON . parse ( JSON . stringify ( newval ) ) ,
186- } as SamInvokeVueState )
187- )
188- } ,
189- deep : true ,
190- } ,
191- } ,
192186 methods : {
193187 resetJsonErrors ( ) {
194188 this . payload . errorMsg = ''
0 commit comments