Challenges with IE Performance in Vue Components

Dealing with a Vue.js typeahead component that was created by a previous developer at my company has been smooth sailing, except when it comes to Internet Explorer 11. In IE 11, there is a strange issue where characters typed into an input field with a keyup function sometimes don't register properly. I suspect this may be due to a performance bottleneck in the codebase. The snippet below contains the problematic code. Removing it eliminates the issue, but that's not a feasible solution. Do you have any recommendations on how I can optimize the performance of this code?


        searchResults: function(e) {
            this.isShown = true;
            this.selectedIndex = 0;
            this.filterOptions();

            if (this.wildcardSearch) {
                var searchObj = {}
                searchObj[this.displayProp] = 'Search For: <strong>' + this.search + '</strong>'
                this.matches.unshift(searchObj)
            }
            // Show first 5 results
            this.matches = this.matches.splice(0, 5);
        },
        filterOptions: function() {
            var lowSearch = this.search.toLowerCase();
            var that = this;
            if (this.search) { // don't filter on empty string
                this.matches = this.options.map(function(o) {
                    if (o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1)
                        return o
                }).filter(function(o) {
                    return o
                });
            }
        },
    

Answer №1

Using both the map and filter functions is unnecessary in this scenario. It seems like the map function is basically functioning as a filter, rendering the actual filter function redundant.

Perhaps consider simplifying it to:

this.matches = this.options.filter(function(o) {
  return o[that.displayProp].toLowerCase().indexOf(lowSearch) > -1
})

In terms of performance impact, I don't foresee any major issues with this approach. However, the usage of both functions could be optimized for better readability and efficiency (I would have mentioned this as a comment if possible).

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

Executing a cloud function from an Angular application utilizing specific parameters

I am currently working on an Angular + Firebase application. Within my Cloud Functions, I have the following function: export const getUserByEmail = functions.https.onRequest((request, response) => { const email = request.body.email admin.auth(). ...

What causes the v-for in a template to only update when the input text changes?

I'm currently working on a Vue.js code, but I'm facing an issue where the template isn't updating when new data is added to the input text. My goal is for the list to update when the @click event occurs. Visit this link for reference metho ...

Utilize jQuery to assign a distinct class to every seventh element within a set

For my blog page, I am looking to create a set of posts with the same HTML structure as shown below: <article class="post"> post 1 </article> My goal is to assign a specific sequence of classes ('medium', 'small', ' ...

Text element within a container of unspecified dimensions

I find it challenging to explain what I have in mind without a visual reference: https://i.sstatic.net/5MSVr.png Some Background - There are certain aspects that can't be altered or shouldn't be changed: On my blog's front page, I utilize ...

How do I convert the object value/data to lowercase in JavaScript using underscore for an HTML5 document?

I am working with an array of objects (arr) where each object consists of 3 properties (Department, Categories, ProductTypes). The values for these properties are a mix of upper and lower case. To perform a comparison between arr and a search filter (alrea ...

Transition one background image into another using background positioning

Snippet of code: https://jsfiddle.net/foy4m43j/ HTML: <div id="background"></div> CSS: #background { background-image: url("http://i.imgur.com/hH9IWA0.png"); background-position: 0 0; background-repeat: repea ...

To compare two JSON files that contain identical values but different keys in order to generate a consolidated table

My goal is to create a comprehensive table by merging data from two different JSON files. One file contains names, work positions, and ages, while the other file includes emails, names, and job roles. The challenge lies in the fact that they use different ...

How to successfully integrate Materializecss from a CDN and enable the select dropdown functionality in ReactJS?

In my ReactJS project, I am utilizing materializecss by including it from its CDN link: <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> </head> <body> <s ...

Picture not appearing on the webpage due to a connection issue with the sqlite database

I am working on creating a user profile feature where users can upload their profile picture. The uploaded picture is saved in local storage within a specific directory, and the URL of this image is then stored in the database linked to the connected user. ...

Maximizing Content Width in FullCalendar v5 to Ensure Screen Compatibility

As I develop a calendar and timeline view using fullcalendar v5, my clients are requesting a month view that displays the entire month without any scroll bars. While I am aware of setting the contentHeight to auto, there seems to be no option for adjusting ...

"Node JS is throwing an Error [ERR_HTTP_HEADERS_SENT] because headers cannot be set after they have already been sent to the client

I'm having trouble updating a specific data entry using its ID, but I keep encountering the error mentioned above. My update process involves searching the database for the ID first and then saving the updated data to MongoDB. Below is a snippet of ...

Utilizing Fullcalendar 5 in conjunction with Angular: Embedding Components within Events

Recently, my team made the transition from AngularJS to Angular 12. With this change, I upgraded Fullcalendar from version 3 to version 5 and started using the Angular implementation of Fullcalendar: https://fullcalendar.io/docs/angular While navigating t ...

Saving functions in the localStorage API of HTML5: A step-by-step guide

I have encountered an issue while trying to store an array in local storage using JSON.stringify. The array contains functions (referred to as promises) within an object, but it seems that when I convert the array to a string, the functions are removed. Su ...

refreshing the table with data that has been refined

Here is the code snippet provided. I have successfully developed a filter to clear a table and retrieve data based on user-specified last name criteria. However, I am struggling with repopulating the table with the filtered results. Possible issues inclu ...

I keep getting an error saying "wallet.connect() is not a function," even though it was working perfectly just a few

`` I'm currently working on the FCC solidity course and I've reached the 7:45 mark. Everything was running smoothly until I encrypted the RPC url, private key, and password. Now, when trying to connect my wallet variable to the provider variable ...

Steps for incorporating one item into another object

I'm struggling to add an object to another object. I've created an object with two properties and now I want to assign it to another object. $scope.urlMappings = {}; $scope.Mapping = function() { ...

Troubleshooting VueJS: Issue with $router.push and passing query parameters

In my NuxtJS(v. 2.10.2) application, there is a URL structure that includes the post's id like this: /post?pid=5e4844e34202d6075e593062. The URL works fine and loads the post based on the value of the pid query parameter. However, when a user adds ...

Dealing with a Promise and converting it into an array: a step-by-step

I am encountering difficulties progressing with my Promise returned from the getPostedPlaces() function. After executing getAll(), an Array is displayed as shown below. Although the array appears to be correct, I am unsure how to make the getAll() function ...

How to use && operator to validate time in ajax requests

I am currently grappling with time validation and feeling a bit perplexed about how to effectively validate both the start_time and end_time using &&. Here is the code I have been working on: var re = /^(\d{1,2}):(\d{2})([ap]m)?$/; //St ...

Implementing jquery to dynamically adjust the height based on certain conditions

When resizing the window, if the height of #cat is less than the height of #dog, the height of #cat should be set equal to the height of #dog. $(window).resize(function() { if ( $('#cat').height() < $('#dog').height() ) { $(& ...