Skip to content

Commit 6b0dd9e

Browse files
authored
Merge pull request #44 from ekhaled/dev-helper-gh-10
fix for ekhaled/svelte-hot-loader#10
2 parents 6d93789 + e85d715 commit 6b0dd9e

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ function makeHot(id, code, hotOptions) {
88
const options = JSON.stringify(hotOptions);
99
const replacement = `
1010
11-
let proxyComponent = $2;
12-
1311
if (module.hot) {
1412
1513
const { configure, register, reload } = require('svelte-loader/lib/hot-api');
@@ -19,14 +17,15 @@ if (module.hot) {
1917
if (!module.hot.data) {
2018
// initial load
2119
configure(${options});
22-
proxyComponent = register(${id}, $2);
20+
$2 = register(${id}, $2);
2321
} else {
2422
// hot update
25-
reload(${id}, proxyComponent);
23+
$2 = reload(${id}, $2);
2624
}
2725
}
2826
29-
export default proxyComponent;
27+
28+
export default $2;
3029
`;
3130

3231
return code.replace(/(export default ([^;]*));/, replacement);

lib/hot-api.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ export function register(id, component) {
1818
instances: []
1919
});
2020

21-
return createProxy(id);
21+
//create the proxy itself
22+
const proxy = createProxy(id);
23+
24+
//patch the registry record with proxy constructor
25+
const record = Registry.get(id);
26+
record.proxy = proxy;
27+
Registry.set(id, record);
28+
29+
return proxy;
2230
}
2331

2432
export function reload(id, component) {
@@ -33,8 +41,11 @@ export function reload(id, component) {
3341

3442
Registry.set(id, record);
3543

36-
//re-render the proxies
44+
//re-render the proxy instances
3745
record.instances.slice().forEach(function(instance) {
3846
instance && instance._rerender();
3947
});
48+
49+
//return the original proxy constructor that was `register()`-ed
50+
return record.proxy;
4051
}

0 commit comments

Comments
 (0)