From f372a9403b91f5df1c3d8cc90fe5ec50930edab4 Mon Sep 17 00:00:00 2001 From: gtm-nayan Date: Fri, 8 Apr 2022 08:21:05 +0545 Subject: [PATCH 1/6] return value from setContext --- src/runtime/internal/lifecycle.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index bb3df3d29526..3b3c2f5f71ec 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -46,8 +46,9 @@ export function createEventDispatcher< }; } -export function setContext(key, context: T) { +export function setContext(key, context: T): T { get_current_component().$$.context.set(key, context); + return context; } export function getContext(key): T { From 897254b7aee33e3c6bfc3a92413473282fb80daf Mon Sep 17 00:00:00 2001 From: Nayan Gautam Date: Fri, 8 Apr 2022 02:55:45 +0000 Subject: [PATCH 2/6] update docs --- site/content/docs/03-run-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 636a98834d3e..a0d3f4148cf1 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -148,7 +148,7 @@ setContext(key: any, context: any) --- -Associates an arbitrary `context` object with the current component and the specified `key`. The context is then available to children of the component (including slotted content) with `getContext`. +Associates an arbitrary `context` object with the current component and the specified `key` and returns that object. The context is then available to children of the component (including slotted content) with `getContext`. Like lifecycle functions, this must be called during component initialisation. From d9dd54cfcbd6636e67f16101d007ffc1b5de23b1 Mon Sep 17 00:00:00 2001 From: Nayan Gautam Date: Sat, 9 Apr 2022 15:18:30 +0000 Subject: [PATCH 3/6] Add test --- test/runtime/samples/context-setcontext-return/_config.js | 5 +++++ test/runtime/samples/context-setcontext-return/main.svelte | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 test/runtime/samples/context-setcontext-return/_config.js create mode 100644 test/runtime/samples/context-setcontext-return/main.svelte diff --git a/test/runtime/samples/context-setcontext-return/_config.js b/test/runtime/samples/context-setcontext-return/_config.js new file mode 100644 index 000000000000..cf3aa1a0ed97 --- /dev/null +++ b/test/runtime/samples/context-setcontext-return/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +
true
+ `, +}; diff --git a/test/runtime/samples/context-setcontext-return/main.svelte b/test/runtime/samples/context-setcontext-return/main.svelte new file mode 100644 index 000000000000..4b13ff12dc72 --- /dev/null +++ b/test/runtime/samples/context-setcontext-return/main.svelte @@ -0,0 +1,7 @@ + + +
{a === b}
\ No newline at end of file From 99ae59af715f90fe6f9cd9e5898c5d46b3e6f950 Mon Sep 17 00:00:00 2001 From: Nayan Gautam Date: Sat, 9 Apr 2022 15:19:41 +0000 Subject: [PATCH 4/6] eof new line --- test/runtime/samples/context-setcontext-return/main.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtime/samples/context-setcontext-return/main.svelte b/test/runtime/samples/context-setcontext-return/main.svelte index 4b13ff12dc72..d878f5bd757e 100644 --- a/test/runtime/samples/context-setcontext-return/main.svelte +++ b/test/runtime/samples/context-setcontext-return/main.svelte @@ -4,4 +4,4 @@ let b = setContext('foo', a); -
{a === b}
\ No newline at end of file +
{a === b}
From 54ac8dd0507e52debd8770a7a96861e1b19d944d Mon Sep 17 00:00:00 2001 From: Nayan Gautam Date: Sat, 9 Apr 2022 15:21:19 +0000 Subject: [PATCH 5/6] pacify the linter --- test/runtime/samples/context-setcontext-return/_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtime/samples/context-setcontext-return/_config.js b/test/runtime/samples/context-setcontext-return/_config.js index cf3aa1a0ed97..28a78f13598a 100644 --- a/test/runtime/samples/context-setcontext-return/_config.js +++ b/test/runtime/samples/context-setcontext-return/_config.js @@ -1,5 +1,5 @@ export default { html: `
true
- `, + ` }; From 5ca66638421466d13d506fd07927080f5e8b5d82 Mon Sep 17 00:00:00 2001 From: Nayan Gautam Date: Sat, 9 Apr 2022 15:24:53 +0000 Subject: [PATCH 6/6] const and tabs --- test/runtime/samples/context-setcontext-return/main.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtime/samples/context-setcontext-return/main.svelte b/test/runtime/samples/context-setcontext-return/main.svelte index d878f5bd757e..87153ee8465a 100644 --- a/test/runtime/samples/context-setcontext-return/main.svelte +++ b/test/runtime/samples/context-setcontext-return/main.svelte @@ -1,7 +1,7 @@
{a === b}