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 |
| --- | --- | --- |
| `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
```js
const { head, html, css } = App.render(
// props
{ answer: 42 },
// slots
{ 'slot-a': (lets) => 'hello world' },
// contexts
new Map([['context-key', 'context-value']]),
// options
{
slots: { 'slot-a': (lets) => 'hello world' },
context: new Map([['context-key', 'context-value']]),
}
);
```

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

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

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

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

Loading…
Cancel
Save