@@ -84,10 +84,9 @@ const get_current_component_safe = () => {
8484export const createProxiedComponent = (
8585 Component ,
8686 initialOptions ,
87- { onInstance, onMount, onDestroy }
87+ { allowLiveBinding , onInstance, onMount, onDestroy }
8888) => {
8989 let cmp
90- let last
9190 let options = initialOptions
9291
9392 const isCurrent = _cmp => cmp === _cmp
@@ -139,6 +138,9 @@ export const createProxiedComponent = (
139138 return comp
140139 }
141140
141+ targetCmp . $$ . on_before_hmr = [ ]
142+ targetCmp . $$ . on_hmr = [ ]
143+
142144 // `conservative: true` means we want to be sure that the new component has
143145 // actually been successfuly created before destroying the old instance.
144146 // This could be useful for preventing runtime errors in component init to
@@ -161,6 +163,11 @@ export const createProxiedComponent = (
161163 ) => {
162164 const restore = captureState ( targetCmp )
163165 assignOptions ( target , anchor , restore , preserveLocalState )
166+
167+ const callbacks = cmp . $$ . on_hmr
168+
169+ const afterCallbacks = callbacks . map ( fn => fn ( cmp ) ) . filter ( Boolean )
170+
164171 const previous = cmp
165172 if ( conservative ) {
166173 try {
@@ -180,9 +187,17 @@ export const createProxiedComponent = (
180187 // previous can be null if last constructor has crashed
181188 previous . $destroy ( )
182189 }
183- cmp = createComponent ( Component , restore , last )
184- last = cmp
190+ cmp = createComponent ( Component , restore , cmp )
185191 }
192+
193+ cmp . $$ . hmr_cmp = cmp
194+
195+ for ( const fn of afterCallbacks ) {
196+ fn ( cmp )
197+ }
198+
199+ cmp . $$ . on_hmr = callbacks
200+
186201 return cmp
187202 }
188203
@@ -240,9 +255,12 @@ export const createProxiedComponent = (
240255 }
241256 }
242257
243- const parentComponent = get_current_component_safe ( )
258+ const parentComponent = allowLiveBinding
259+ ? current_component
260+ : get_current_component_safe ( )
244261
245262 cmp = new Component ( options )
263+ cmp . $$ . hmr_cmp = cmp
246264
247265 instrument ( cmp )
248266
0 commit comments