Skip to content

Commit

Permalink
feat(svelte): demonstrate fine-grained reactivity (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Oct 26, 2023
1 parent 84ec093 commit b1bf303
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h2>My Profile</h2>
<p>Username: {user.value.username}</p>
<p>Email: {user.value.email}</p>
<button on:click={() => user.updateUsername("Jane")}>
<button on:click={() => (user.username = "Jane")}>
Update username to Jane
</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
export default function createUserState(initial) {
let user = $state(initial);
let username = $state(initial.username);
return {
get value() {
return user;
...initial,
get username() {
return username;
},
updateUsername(newUsername) {
user = {
...user,
username: newUsername,
};
set username(value) {
username = value;
},
};
}

0 comments on commit b1bf303

Please sign in to comment.