0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00

get store() to work with nested components in SSR compiler

This commit is contained in:
Rich Harris 2017-12-15 20:58:06 -05:00
parent 733e949b06
commit f7c540b4ed
6 changed files with 31 additions and 15 deletions

View File

@ -81,10 +81,8 @@ export default function ssr(
if (storeProps.length > 0) {
const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`
if (options.store) {
if (options.store || templateProperties.store) {
initialState.push(`options.store.${initialize}`);
} else if (templateProperties.store) {
initialState.push(`%store().${initialize}`);
}
}
@ -116,6 +114,7 @@ export default function ssr(
}
var result = { head: '', addComponent };
${templateProperties.store && `options.store = %store();`}
var html = ${name}._render(result, state, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\\n');

View File

@ -159,7 +159,7 @@ describe("runtime", () => {
target,
hydrate,
data: config.data,
store: config.store
store: (config.store !== true && config.store)
}, config.options || {});
const component = new SvelteComponent(options);

View File

@ -0,0 +1 @@
<p>It's nice to see you, {{$name}}.</p>

View File

@ -1,9 +1,17 @@
export default {
html: `<h1>Hello world!</h1>`,
store: true, // TODO remove this in v2
html: `
<h1>Hello world!</h1>
<p>It's nice to see you, world.</p>
`,
test(assert, component, target) {
component.store.set({ name: 'everybody' });
assert.htmlEqual(target.innerHTML, `<h1>Hello everybody!</h1>`);
assert.htmlEqual(target.innerHTML, `
<h1>Hello everybody!</h1>
<p>It's nice to see you, everybody.</p>
`);
}
};

View File

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

View File

@ -113,7 +113,7 @@ describe("ssr", () => {
try {
const component = require(`../runtime/samples/${dir}/main.html`);
const { html } = component.render(config.data, {
store: config.store
store: (config.store !== true) && config.store
});
if (config.html) {