Skip to content

Task: Establish definitive approach to contextual value binding #104

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

Closed
2 of 3 tasks
emmnull opened this issue Oct 6, 2022 · 1 comment
Closed
2 of 3 tasks

Task: Establish definitive approach to contextual value binding #104

emmnull opened this issue Oct 6, 2022 · 1 comment
Assignees

Comments

@emmnull
Copy link
Member

emmnull commented Oct 6, 2022

Task Description

To reduce explicit prop drilling in templates and facilitate composability of components using slots, we favor the use of contexts across related components within their respective trees. Though, a challenge arises when considering that svelte contexts are, by nature, non-reactive. We have to pass reactive values as stores, but we want to keep the outer component's props as non-stores (that is, keep the outer component's API as is, where one can bind:value to a simple string).

How should we bind the passed prop value with the component's store-ized value for it to be two way?

To put it in other terms, what we are essentially looking for here is a way to manually hook into any variable's reactivity, regardless of its data-type (primitive or not), with capabilities of get and set methods, without having to declare a reactive statement using the $: syntax.

Reading

List of actions

  • Design a robust but simple system
  • Decide if logic should be taken aside in abstract (purely functional) components, helpers, or simply kept within primitive components
  • Document adopted system explicitely in primitive dir's readme
@emmnull emmnull self-assigned this Oct 6, 2022
@emmnull
Copy link
Member Author

emmnull commented Oct 7, 2022

Opted for simply proxying value to a contextual _value writable using two reactive statements:

export let value: string;

const _value = writable(value);

$: value = $_value;
$: _value.set(value) // Do not use "$_value = value" else results in circular dependency

For the time being, this seems like the simplest most straighforward. To revisit if pitfalls are encountered.

@emmnull emmnull closed this as completed Oct 7, 2022
@emmnull emmnull closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
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

No branches or pull requests

1 participant