Skip to content

docs: Update README.md #520

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

Merged
merged 3 commits into from
Dec 15, 2023
Merged

docs: Update README.md #520

merged 3 commits into from
Dec 15, 2023

Conversation

matzar
Copy link
Contributor

@matzar matzar commented Oct 13, 2023

Docs: 04-updating-arrays-and-objects

Ensured clarity in the example code by defining the obj object. This ensures that readers understand the context and structure of the object being modified in the reactivity example.

Because it is possible to trigger reactivity by referencing foo.bar in the template instead of obj.foo.bar, the following will trigger reactivity:

<script>
    let obj = { foo: { bar: 'old' } };
    const foo = obj.foo;
    
    function updateFooBar() {
        foo.bar = 'baz';
    }
</script>

<button on:click={updateFooBar}>Update foobar</button>
<!-- referencing the variable with `foo.bar` - triggers reactivity -->
<p>baz is: {foo.bar}</p>

However, the next example will not, and will require obj = obj reassignment:

<script>
    let obj = { foo: { bar: 'old' } };
    const foo = obj.foo;
    
    function updateFooBar() {
        foo.bar = 'baz';
        // uncomment below to trigger reactivity
        // obj = obj 
    }
</script>

<button on:click={updateFooBar}>Update foobar</button>
<!-- referencing the variable with `obj.foo.bar` - does **not** trigger reactivity -->
<p>baz is: {obj.foo.bar}</p>

In this case, {obj.foo.bar} does not trigger reactivity when foo.bar is updated, unless obj is reassigned (with obj = obj).

By including the definition of the obj object, we aim to elucidate the structure and context in which the reactivity example operates, ensuring a clearer understanding for the reader.

docs: 04-updating-arrays-and-objects, add `let obj = { foo: { bar: 'old' } };` for more clarity
@vercel
Copy link

vercel bot commented Oct 13, 2023

@matzar is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@Rich-Harris
Copy link
Member

thanks!

@Rich-Harris Rich-Harris merged commit da3e539 into sveltejs:main Dec 15, 2023
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.

2 participants