From 36cd61f0c634d098b822420aaac154238efb00ed Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 28 Feb 2021 02:52:35 +0800 Subject: [PATCH] use maps instead --- site/content/docs/03-run-time.md | 2 +- src/runtime/internal/Component.ts | 2 +- test/runtime/samples/constructor-pass-context/_config.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 293f2c65a5..2f351fee96 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -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 diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index c2615ac85f..32de46506a 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -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(), diff --git a/test/runtime/samples/constructor-pass-context/_config.js b/test/runtime/samples/constructor-pass-context/_config.js index 43c5266165..3348addf08 100644 --- a/test/runtime/samples/constructor-pass-context/_config.js +++ b/test/runtime/samples/constructor-pass-context/_config.js @@ -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, '
svelte
');