First, thanks a million for your tutorial, it's helping a lot with Svelte.
Just a detail: if I am not mistaken, postsUpdated can be dropped and we can apply splice on posts, since posts and postsUpdated point both at the same array...
postsUpdated = posts and posts = postsUpdated don't copy the arrays, they point to the same array so no need to assign posts and postsUpdated
function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); let postsUpdated = posts; postsUpdated.splice(index, 1, post); posts = postsUpdated;
function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); posts.splice(index, 1, post);
First, thanks a million for your tutorial, it's helping a lot with Svelte.
Just a detail: if I am not mistaken, postsUpdated can be dropped and we can apply splice on posts, since posts and postsUpdated point both at the same array...
postsUpdated = posts and posts = postsUpdated don't copy the arrays, they point to the same array so no need to assign posts and postsUpdated
function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); let postsUpdated = posts; postsUpdated.splice(index, 1, post); posts = postsUpdated;function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); posts.splice(index, 1, post);