Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing in context in constructor #6032

Merged

Conversation

tanhauhau
Copy link
Member

@tanhauhau tanhauhau commented Feb 27, 2021

This allows passing in context through the Svelte Component Constructor API

import Component from './Component.svelte';

const context = new Map();
map.set('a', 123);
map.set('b', 456);

new Component({
   target: document.body,
   context: context,
});

Before submitting the PR, please make sure you do the following

  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@tanhauhau tanhauhau force-pushed the tanhauhau/set-context-in-constructor branch from 8d6c9af to a7d66ac Compare February 27, 2021 18:45
src/runtime/tsconfig.json Outdated Show resolved Hide resolved
@Conduitry
Copy link
Member

Do we want a way to do this for SSR components as well?

@tanhauhau
Copy link
Member Author

That make sense, let me add for SSR components as well.

@tanhauhau tanhauhau force-pushed the tanhauhau/set-context-in-constructor branch from ee65224 to 993a783 Compare March 2, 2021 07:15
@Conduitry
Copy link
Member

The new SSR test is failing, which I can also reproduce locally. I'm not sure what's going on there. It does pass if I add solo: true to it to run only that test.

@tanhauhau tanhauhau force-pushed the tanhauhau/set-context-in-constructor branch from 993a783 to 43402c5 Compare March 27, 2021 16:21
@tanhauhau tanhauhau force-pushed the tanhauhau/set-context-in-constructor branch from 43402c5 to 6d82512 Compare March 27, 2021 16:27
@Conduitry Conduitry merged commit 6c5257b into sveltejs:master Mar 31, 2021
pfz pushed a commit to pfz/svelte that referenced this pull request Apr 25, 2021
Co-authored-by: Conduitry <git@chor.date>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants