Skip to content

Commit 90b3fbc

Browse files
committed
cleaning code a little bit
1 parent 0c3e22b commit 90b3fbc

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/svelte-hmr/runtime/proxy.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ const relayInternalMethods = (proxy, cmp) => {
8888
})
8989
}
9090

91+
// proxy custom methods
9192
const copyComponentProperties = (proxy, cmp, previous) => {
92-
//proxy custom methods
93-
const props = Object.getOwnPropertyNames(Object.getPrototypeOf(cmp))
9493
if (previous) {
9594
previous.forEach(prop => {
9695
delete proxy[prop]
9796
})
9897
}
99-
return props.filter(prop => {
98+
99+
const props = Object.getOwnPropertyNames(Object.getPrototypeOf(cmp))
100+
const wrappedProps = props.filter(prop => {
100101
if (!handledMethods.includes(prop) && !forwardedMethods.includes(prop)) {
101102
Object.defineProperty(proxy, prop, {
102103
configurable: true,
@@ -113,6 +114,8 @@ const copyComponentProperties = (proxy, cmp, previous) => {
113114
return true
114115
}
115116
})
117+
118+
return wrappedProps
116119
}
117120

118121
// everything in the constructor!
@@ -165,7 +168,7 @@ class ProxyComponent {
165168
if (conservativeDestroy) {
166169
replaceOptions.conservativeDestroy = true
167170
}
168-
setComponent(cmp.$replace(current.Component, replaceOptions))
171+
cmp.$replace(current.Component, replaceOptions)
169172
} catch (err) {
170173
setError(err, target, anchor)
171174
if (
@@ -236,11 +239,12 @@ class ProxyComponent {
236239

237240
try {
238241
let lastProperties
239-
const _cmp = createProxiedComponent(current.Component, options, {
242+
createProxiedComponent(current.Component, options, {
240243
allowLiveBinding: current.hotOptions.allowLiveBinding,
241244
onDestroy,
242245
onMount: afterMount,
243246
onInstance: comp => {
247+
setComponent(comp)
244248
// WARNING the proxy MUST use the same $$ object as its component
245249
// instance, because a lot of wiring happens during component
246250
// initialisation... lots of references to $$ and $$.fragment have
@@ -252,7 +256,6 @@ class ProxyComponent {
252256
lastProperties = copyComponentProperties(this, comp, lastProperties)
253257
},
254258
})
255-
setComponent(_cmp)
256259
} catch (err) {
257260
const { target, anchor } = options
258261
setError(err, target, anchor)
@@ -375,8 +378,8 @@ export function createProxy({
375378
if (!fatalError) {
376379
fatalError = true
377380
logError(
378-
`Unrecoverable error in ${debugName}: next update will trigger a ` +
379-
`full reload`
381+
`Unrecoverable HMR error in ${debugName}: ` +
382+
`next update will trigger a full reload`
380383
)
381384
}
382385
throw err

0 commit comments

Comments
 (0)