fix for code review

pull/6032/head
tanhauhau 6 years ago
parent adf6085d9c
commit 6d82512e82

@ -1088,16 +1088,22 @@ You can call the `.render()` with the following parameters:
| option | default | description | | option | default | description |
| --- | --- | --- | | --- | --- | --- |
| `props` | `{}` | An object of properties to supply to the component | `props` | `{}` | An object of properties to supply to the component
| `slots` | `{}` | A object of slots to supply to the component | `options` | `{}` | An object of options
The `options` object takes in the following properties:
| key | default | description |
| --- | --- | --- |
| `slots` | `{}` | slots to supply to the component
| `context` | `new Map()` | A `Map` of context key-value pairs to supply to the component | `context` | `new Map()` | A `Map` of context key-value pairs to supply to the component
```js ```js
const { head, html, css } = App.render( const { head, html, css } = App.render(
// props // props
{ answer: 42 }, { answer: 42 },
// slots // options
{ 'slot-a': (lets) => 'hello world' }, {
// contexts slots: { 'slot-a': (lets) => 'hello world' },
new Map([['context-key', 'context-value']]), context: new Map([['context-key', 'context-value']]),
}
); );
``` ```

@ -97,7 +97,7 @@ export function create_ssr_component(fn) {
} }
return { return {
render: (props = {}, slots = {}, context = new Map()) => { render: (props = {}, { slots = {}, context = new Map() } = {}) => {
on_destroy = []; on_destroy = [];
const result: { const result: {

@ -3,7 +3,7 @@
"include": ["."], "include": ["."],
"compilerOptions": { "compilerOptions": {
"lib": ["es2017", "dom", "dom.iterable"], "lib": ["es2015", "dom", "dom.iterable"],
"target": "es2015", "target": "es2015",
"types": [], "types": [],

@ -23,10 +23,10 @@ export default {
const Component = require('./Component.svelte').default; const Component = require('./Component.svelte').default;
const called = []; const called = [];
const { html } = Component.render(undefined, undefined, new Map([ const { html } = Component.render(undefined, { context: new Map([
['key', 'svelte'], ['key', 'svelte'],
['fn', (value) => called.push(value)] ['fn', (value) => called.push(value)]
])); ]) });
assert.htmlEqual(html, '<div>svelte</div><button></button>'); assert.htmlEqual(html, '<div>svelte</div><button></button>');
} }
}; };

@ -13,6 +13,7 @@ import {
shouldUpdateExpected, shouldUpdateExpected,
mkdirp mkdirp
} from '../helpers'; } from '../helpers';
import { set_current_component } from '../../internal';
function tryToReadFile(file) { function tryToReadFile(file) {
try { try {
@ -127,6 +128,8 @@ describe('ssr', () => {
showOutput(dir, { generate: 'ssr', format: 'cjs' }); showOutput(dir, { generate: 'ssr', format: 'cjs' });
err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`; err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`;
throw err; throw err;
} finally {
set_current_component(null);
} }
}); });
}); });
@ -223,6 +226,8 @@ describe('ssr', () => {
showOutput(cwd, compileOptions); showOutput(cwd, compileOptions);
throw err; throw err;
} }
} finally {
set_current_component(null);
} }
}); });
}); });

Loading…
Cancel
Save