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

[feat] Make setContext return the value that was passed in #7432

Merged
merged 6 commits into from Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/content/docs/03-run-time.md
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion src/runtime/internal/lifecycle.ts
Expand Up @@ -46,8 +46,9 @@ export function createEventDispatcher<
};
}

export function setContext<T>(key, context: T) {
export function setContext<T>(key, context: T): T {
get_current_component().$$.context.set(key, context);
return context;
}

export function getContext<T>(key): T {
Expand Down