Merge pull request #1116 from UnwrittenFun/fix/ssr-nested-store

Fix passing a store to nested components on server side
pull/1105/merge
Rich Harris 7 years ago committed by GitHub
commit 7bf743ca96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -114,7 +114,6 @@ export default function ssr(
} }
var result = { head: '', addComponent }; var result = { head: '', addComponent };
${templateProperties.store && `options.store = %store();`}
var html = ${name}._render(result, state, options); var html = ${name}._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n'); var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n');
@ -130,6 +129,7 @@ export default function ssr(
} }
${name}._render = function(__result, state, options) { ${name}._render = function(__result, state, options) {
${templateProperties.store && `options.store = %store();`}
__result.addComponent(${name}); __result.addComponent(${name});
state = Object.assign(${initialState.join(', ')}); state = Object.assign(${initialState.join(', ')});

@ -0,0 +1,13 @@
<h1>Hello, {{$name}}!</h1>
<script>
import { Store } from '../../../../store.js';
export default {
store () {
return new Store({
name: 'world'
});
},
};
</script>

@ -0,0 +1,7 @@
export default {
store: true, // TODO remove this in v2
html: `
<h1>Hello, world!</h1>
`,
};

@ -0,0 +1,11 @@
<Nested/>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>
Loading…
Cancel
Save