Guide to arranging Keyed blocks in Svelte

After creating a store filled with user data, I am looking to sort the users based on different criteria.

store.js

export const users = writable([
  {
    "id": 11,
    "name": "Kepler",
  },
  {
    "id": 13,
    "name": "Planck",
  },
// more users added here

To achieve this, I am utilizing orderBy from Lodash.

Case A: Without using keyed each blocks, orderBy functions correctly.

App.svelte

{#each _.orderBy($users, [param], [order]) as user}
  <div>{user.id} {user.name}</div>
{/each}

However, when making changes to the store or removing items, updates do not work properly. You can find a detailed explanation in Svelte's documentation.

Case B: With a keyed each block, updates function as expected but orderBy does not.

App.svelte

{#each _.orderBy($users, [param], [order]) as user (user.id)}
    <div>{user.id} {user.name}</div>
{/each}

Check out a real example on Svelte REPL here.

Visit the link and use the buttons to switch between ascending and descending order.

I may be overlooking something related to keyed each blocks and would appreciate insights from Svelte experts to resolve this issue.

Answer №1

The latest update, version 3.39, has resolved the bug that was present in version 3.38.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exhilarating Javascript document with fresh lines and line breaks

In my current project, I am dynamically generating a JavaScript page using PHP and .htaccess to convert .php files into .js files. Everything is functioning properly, except for the output of the JavaScript code. For example: $data = array('one&apo ...

Restart jQuery animation upon modal closure

I'm facing an issue with an animation where a bottle gets filled up to a specific point from data stored in the database. The problem arises when I open and close a modal, as the animation continues running even after the modal is closed. My goal is t ...

Tips for organizing JSON information in ReactJS

Could someone lend a hand with sorting JSON data in ReactJs? I'm having trouble getting it to work properly. Also, if I want to sort by title, would it be the same process? Thanks! This is what I've tried so far: componentDidMount() { ...

The inArray() function will always return a negative result

I'm encountering an issue and need some help resolving it - whenever I use inArray(), I consistently receive a value of -1. Here's a breakdown of what I'm trying to achieve : <!-- HTML Markup --> <nav class="navigation clearfix"&g ...

JS click event listener is failing to activate the function as intended

In an attempt to create a modal window, I am facing issues with adding a click event listener to a div that should modify the CSS style of another element. The goal is to change the display property from 'none' to 'border-box' when the ...

Creating a countdown timer with setTimeout in JavaScript

I'm working on developing a countdown timer using jQuery. After referencing several examples, I have written the following code. However, I am facing an issue where the time is not being displayed and I cannot seem to identify what is causing the prob ...

Seeking guidance on utilizing JavaScript for implementing an onclick event

I am exploring the realm of Event tracking with Google Analytics. To make this happen, I know that I must include an onclick attribute to select links (those specifically requested for tracking) in the following manner: <a href="http://www.example.com" ...

Vue Component, switching state

Feeling like I'm losing it, this should be really simple but it's not working... The idea is that when the link is clicked, the display property toggles between true and false. However, it's not working as expected. Vue.component('d ...

Exploring outside iframe data

My webpage includes an iframe A with a src attribute that links to a URL containing another embedded iframe B. I'm trying to figure out if it's possible to access the src of this nested iframe B. However, it appears that browser security measures ...

Unexpected results occur when accessing data in $uibModal.open() within Angular JS causing it to

Here is the code snippet that is causing the issue of returning undefined items in AngularJS: App.js code console.log('single page application script is working'); var myApp = angular.module("demoApp", ["ngRoute", 'ui.bootstrap',&apos ...

JavaScript may experience delays when setting the height

Two html tables I have, filled with various elements like span, input, select, and more. My goal is to make sure that the rows in both tables are of equal height. Unfortunately, simply setting the 'height' attribute on tr or td did not yield the ...

Creating images or PDFs from HTML with CSS filters: a guide

Looking for someone who has experience creating images or PDFs from HTML code. The HTML contains images with CSS filters such as sepia and grayscale. If you have worked on this type of project before, I would love to hear about your experience. <img cl ...

Determine the precise boundaries of the React component

I am working with a basic ellipse element: <span style={{ width: /*someWith*/, height: /*someHeight*/, borderRadius: "50%" }}/> and, I am using getBoundingClientRect() to retrieve its bounds (displayed in blue). https://i.ssta ...

Instructions on changing class when input length is not equal to zero

Is there a way to dynamically add a class to an input[type="email"] when its length is greater than 0 and remove it when the input length reaches 0? I'm not very proficient in JavaScript, so the solution could be implemented using vue.js or pure Java ...

JSON object fails to iterate with ng-repeat

It must be the scorching temperature... Having a json object that I'm eager to loop through using ng-repeat, it should be straightforward, but alas! it's just not cooperating. Here's the HTML snippet: <a data-ng-repeat="x in template.m ...

Issue with Jquery change event not functioning as expected

My webpage consists of the following HTML code: <form id="fileuploadform"> <input type="file" id="fileupload" name="fileupload" /> </form> Accompanied by this snippet of jQuery code: $(':file').change(function(){ var ...

The unrevealed node that is requesting the module is leading to an undefined outcome

I'm facing an issue where I need to import var server = require('../../index.js'); in my foo-dao.js file. This is necessary for accessing a hapi server plugin without passing it through the hapi request object from controller to dao. The pr ...

a user-friendly database solution for storing data in HTML 5 and Google Drive

Greetings, I am currently faced with the following dilemma: As I work on my angular 2 application, I find myself needing to save certain data. Personally, I have a preference for saving data in JSON format. Here is the scenario: Imagine a todo list where ...

After implementing global navigation guards in Vue-router, an unexpected error message stating "Uncaught TypeError: Cannot read property 'matched' of undefined" is being thrown

After successfully navigating the login process and implementing user-role-based routing, I proceeded to set up authentication guards for different URLs. Though it initially seemed straightforward, I encountered an error that I haven't been able to t ...

Discover a scenario in which an identification number is contained within an array

For my Node.js + MongoDB project, I am utilizing sails.js and am currently faced with the challenge of loading all the groups associated with a particular user. Each Group object contains an array of user IDs as follows: Group { users: array } I' ...