Skip to content

Commit

Permalink
use maps instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Feb 27, 2021
1 parent cef1710 commit ee65224
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion site/content/docs/03-run-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ The following initialisation options can be provided:
| `target` | **none** | An `HTMLElement` to render to. This option is required
| `anchor` | `null` | A child of `target` to render the component immediately before
| `props` | `{}` | An object of properties to supply to the component
| `context` | `{}` | An object of context to supply to the component
| `context` | `new Map()` | A `Map` of context key-value pairs to supply to the component
| `hydrate` | `false` | See below
| `intro` | `false` | If `true`, will play transitions on initial render, rather than waiting for subsequent state changes

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : options.context ? Object.entries(options.context) : []),
context: new Map(parent_component ? parent_component.$$.context : options.context || []),

// everything else
callbacks: blank_object(),
Expand Down
8 changes: 4 additions & 4 deletions test/runtime/samples/constructor-pass-context/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default {
const called = [];
const component = new Component({
target,
context: {
key: 'svelte',
fn: (value) => called.push(value)
}
context: new Map([
['key', 'svelte'],
['fn', (value) => called.push(value)]
])
});
assert.htmlEqual(target.innerHTML, '<div>svelte</div><button></button>');

Expand Down

0 comments on commit ee65224

Please sign in to comment.