Rendering performance problem with Phaser 3

I’m new to Phaser 3 and seem to have a huge performance problem. I’m making a Wordle clone game that renders a grid and fills it in with colors and letters as users progress in the game. Each item in the game is either something I created using this.add.text or this.add.graphics

When the game starts, the scene is able to render in less than 3ms

By the end of the game, the scene takes more than 45ms

What am I doing wrong and why is it so slow? How can I improve the performance?
enter image description here

enter image description here

BootstrapVue b-table not storing selected rows when changing pages using b-pagination

I have the following b-table and b-pagination in my template:

<b-table
  bordered
  hover
  responsive
  :items="items"
  :fields="fields"
  :sort-by.sync="sortBy"
  :sort-desc.sync="sortDesc"
  sort-icon-left
  :filter="searchFilter"
  @filtered="onFiltered"
  :filter-included-fields="filterOn"
  :per-page="perPage"
  :current-page="currentPage"
  class="table1"
  ref="table1"
  selectable
  @row-selected="selectedRow"
  :tbody-tr-class="styleRow"
>
  <template #cell(selected)="{ rowSelected }">
      <template v-if="rowSelected">
          <span class="sr-only">Selected</span>
      </template>
      <template v-else>
          <span class="sr-only">Not selected</span>
      </template>
  </template>
</b-table>

<b-pagination
  v-model="currentPage"
  :total-rows="totalRows"
  :per-page="perPage"
  align="center"
  limit="15"
></b-pagination>

In my Vue app, I have the following functions for when the user selects a row:

export default {
  data() {
    return {
      items: [],
      sortBy: 'build',
      sortDesc: true,
      searchFilter: '',
      perPage: 11,
      currentPage: 10,
      totalRows: 1,
      fields: [],
      defaultFields: [],
      fieldNames: [],
      filterOn: [],
      selectedInfo: { item: {}, value: {}, field: {} },
      selected: [],
    };
  },
  methods: {
    styleRow(item) {
      if (item.selected) {
        return ['b-table-row-selected', 'table-secondary'];
      }
      return [];
    },
    selectedRow(items) {
      this.selected = items;
    }
  },
};

Here’s the problem: let’s say the user selects a few rows on page 1 of the table, then goes to page 2, and then goes back to page 1. The previously clicked rows are no longer selected. How do I fix this? How do I prevent pagination from resetting the selected rows?

discord.js autorole from custom status

I have an idea but unfortunately, I don’t know how to make this, or if this is possible.

I want that my discord bot gives a role on my server for a specific keyword in the custom status. The role should be removed if the custom status gets removed or changed.

My question is: If it’s possible how can I make a feature like that in the latest discord.js?

JavaScript: Filter out keys from array of objects

This is what my current object looks like.
My question is how to parse this object such that it will return the expected output (without index 0,1,2…) I want a Javascript array of objects, without the key value.

 "contacts": {
  "0": {
    "firstName": "James",
    "lastName": "April",
    "emails": [
      {
        "emailType": "WORK",
        "address": ""
      },
      {
        "emailType": "PERSONAL",
        "address": ""
      }
    ],
    "relationship": "boyfriend",
    "phones": [
      {
        "phoneType": "HOME",
        "phoneNumber": "(456) 888-9999"
      },
      {
        "phoneType": "CELL",
        "phoneNumber": "(789) 123-4567"
      },
    ],
    "callSequence": 0,
    "note": null
  },
  "1": {
    "firstName": "Joe",
    "lastName": "Kimmel",
    "emails": [
      {
        "emailType": "WORK",
        "address": ""
      },
      {
        "emailType": "PERSONAL",
        "address": ""
      }
    ],
    "relationship": "ex-husband",
    "phones": [
      {
        "phoneType": "HOME",
        "phoneNumber": ""
      },
      {
        "phoneType": "CELL",
        "phoneNumber": "(111) 111-1111"
      },
      {
        "phoneType": "WORK",
        "phoneNumber": ""
      }
    ],
    "callSequence": 0,
    "note": null
  },
  "2": {
    "firstName": "Test",
    "lastName": "",
    "emails": [
      {
        "emailType": "WORK",
        "address": "[email protected]"
      },
      {
        "emailType": "PERSONAL",
        "address": "[email protected]"
      }
    ],
    "relationship": "BROTHER-IN-LAW",
    "phones": [
      {
        "phoneType": "HOME",
        "phoneNumber": ""
      },
      {
        "phoneType": "CELL",
        "phoneNumber": ""
      },
      {
        "phoneType": "WORK",
        "phoneNumber": ""
      }
    ],
    "callSequence": 0
  }
}

}

Expected Result
Wihout the indexes 0,1,2 and should be inside an array. So I want the output as array of objects

   "contacts": [{
   {
    "firstName": "James",
    "lastName": "April",
    "emails": [
      {
        "emailType": "WORK",
        "address": ""
      },
      {
        "emailType": "PERSONAL",
        "address": ""
      }
    ],
    "relationship": "boyfriend",
    "phones": [
      {
        "phoneType": "HOME",
        "phoneNumber": "(456) 888-9999"
      },
      {
        "phoneType": "CELL",
        "phoneNumber": "(789) 123-4567"
      },
    ],
    "callSequence": 0,
    "note": null
  },
   {
    "firstName": "Joe",
    "lastName": "Kimmel",
    "emails": [
      {
        "emailType": "WORK",
        "address": ""
      },
      {
        "emailType": "PERSONAL",
        "address": ""
      }
    ],
    "relationship": "ex-husband",
    "phones": [
      {
        "phoneType": "HOME",
        "phoneNumber": ""
      },
      {
        "phoneType": "CELL",
        "phoneNumber": "(111) 111-1111"
      },
      {
        "phoneType": "WORK",
        "phoneNumber": ""
      }
    ],
    "callSequence": 0,
    "note": null
  }]

set focus on iframe contents to allow sound

this is an extension to another question i’ve asked

i want to embed a game on a website and i want it to automaticaly focus on the iframe. but whenever i try anything like iframe.contentWindow.focus() it focuses on the iframe but the iframe doesnt have any sound

the code for the game was written in a special program so the code is all jumbled and hard to comprehend. though i did find a script that can test the audio. what i want is for this to return true.

testAudio(){
  playTestAudio();return _yb1&&g_WebAudioContext&&g_WebAudioContext.state!==_fa1._ga1
}
function playTestAudio() {
  if(_yb1||_zb1)return;
  _zb1=true;
  var _lb1=new Audio(_X91);
  _lb1.controls=false;
  _lb1.autoplay=true;
  _lb1.preload="none";
  document.body.appendChild(_lb1);
  try{
    var _Bb1=_lb1.play();
    if(_Bb1!==undefined) {
      _Bb1.then(function() {
        debug("WebAudio autoplay test passed.");
        _yb1=true;
        _zb1=false;
        _Cb1();
        document.body.removeChild(_lb1)
      }).catch(function(error) {
        console.log("WebAudio autoplay test failed: ",error);
        document.body.removeChild(_lb1);
        _zb1=false;
        _Db1()
      })
    }else {
      console.log("WebAudio autoplay test failed: Playback promise invalid.");
      document.body.removeChild(_lb1);
      _zb1=false;
      _Db1()
    }
  }
  catch(_wC){debug("WebAudio autoplay test failed with exception: "+_wC);
  document.body.removeChild(_lb1);_zb1=false;_Db1()}
}

this is the location of the script file if needed
lacation.scripts.net

Don’t know how to write a specific regular expression

I have a string like this:

“56×74 x567 x7 7889 x97x89xx”.

I need to leave everything except the letter x, which has a left empty space involved. It has to be done by the Match method.
I was trying to do it, but it has not worked at all.
Please, help me.
The result should look like this:

“56×745677 788997x89xx”.

Having a varible in regex?

Hi I have the following code

    const containsAtLeastDigits = (digits, password) => {
  
  const regex = new RegExp(/(?=.{6}).*/g);

  if (regex.test(password)) {
    console.log("yes");
    return false;
  } else {
    console.log("no");
  }
};

containsAtLeastDigits(6, "abcdefg");

Here I have to pass the parameter digits where {6} is defined in regex as interpolation like this ${digits}. Can someone please explain if this is possible to do? I saw a few answers in StackOverflow itself but they are not working.

Using react-select with multiple inputs

I have multiple react-select inputs, each have their own separate options array. The issue i’m having is I’m now sure how to properly store the output of each select input.

I want to use this select output to POST to my backend but i’m unsure how to do it all with a single handler function.

This is what I have so far, i have 2 paragraphs to just output the appropriate result from the select fields but i can’t seem to get it working.

This is the codesandbox i have:

https://codesandbox.io/s/busy-yonath-rlj9e?file=/src/App.js

Setting React state Asynchronous – React useState hook

I am trying to update 1 quote inside of an array of “quotes”

const [quotes, setQuotes] = useState([]);
const [quoteToUpdate, setQuoteToUpdate] = useState(initialValues);

When I click on a switch (checkbox) I set quoteToUpdate with the quoteToUpdate with the selected quote data, and update the switch from true to false or vice versa.

const onCheckboxChange = async (e, selectedQuote) => {
  setQuoteToUpdate({...selectedQuote, [e.target.name]: e.target.checked});
};

The Problem I’m having is, right after I update the quoteUpdate, I need to send the updated object to the backend to update. But since React state is sync, the quoteToUpdate does not get updated instantly but instead queues up.

What I’ve tried:
I’ve tried putting the onSubmit() function inside a useEffect but it’s clearly not working.

useEffect(() => {
  onSubmit(quoteToUpdate);
}, [quoteToUpdate])

onSubmit looks like this:

const onSubmit = (quoteToUpdate) => {
    axiosWithAuth().put('/quotes/' + quoteToUpdate.id, quoteToUpdate)
      .then((res) => {
        const updatedQuote = res.data;
        setQuotes(quotes.map(quote => (
          quote.id === updatedQuote.id ? {...quote, 'is_complete': updatedQuote.is_complete} : quote
          ))
        );

        const alertContent = `quote updated successfully.`;

        halfmoon.stickyAlerts = document.getElementsByClassName("sticky-alerts")[0]
        halfmoon.initStickyAlert({
        content: alertContent, alertType: "alert-success", title: "Successfully updated"
      })
    }).catch(error => {
      console.log(error.message);
    });
}

In native Javascript (or NodeJS) is it possible to chain object or function properties for a function call?

More of an exercise in ‘what-if’, I was wondering if the following was possible:

output = convert(1200).from('mm').to('inches')

where ‘from’ and ‘to’ are functions (or properties) of ‘convert’ as opposed to the more standard:

    output = convert(1200, 'mm', 'inches')

or:

    output = convert(value = 1200, from = 'mm', to = 'inches')

addendum: I’m guessing the closest would be:

output = convert({ value: 1200, from: 'mm', to: 'inches' });
 
function convert({ value, from, to } = {}){
  // ...do stuff here...
}

Wait for nested loops to finish before returning in javascript [duplicate]

I have a list of objects (say staff_comp_array) whose structure is as follows:

staff_comp_array = [{
    "staff_id": "CEB",
    "competency": [{
        "workflow": "Workflow A",
        "task_competency": ["Workflow_A_Task_1", "Workflow_A_Task_2"]
    }, {
        "workflow": "Workflow B",
        "task_competency": ["Workflow_B_Task_1", "Workflow_B_Task_2"]
    }]
},
{
    "staff_id": "XD",
    "competency": [{
        "workflow": "Workflow A",
        "task_competency": ["Workflow_A_Task_3"]
    }, {
        "workflow": "Workflow B",
        "task_competency": ["Workflow_B_Task_2", "Workflow_B_Task_3"]
    }]
}
]

There is a collection in MongoDB which has definitions for each task competency as follows:

{
    "workflow": "Workflow B",
    "tasks": [{
        "task_id": "Workflow_B_Task_1",
        "task_name": "Loading B",
        "task_abbr": "LB"
    }, {
        "task_id": "Workflow_B_Task_2",
        "task_name": "Planning B",
        "task_abbr": "PB"
    },{
        "task_id": "Workflow_B_Task_3",
        "task_name": "Checking B",
        "task_abbr": "CB"
    },{
        "task_id": "Workflow_B_Task_4",
        "task_name": "Review B",
        "task_abbr": "RB"
    }]
},
{
    "workflow": "Workflow A",
    "tasks": [{
        "task_id": "Workflow_A_Task_1",
        "task_name": "Loading A",
        "task_abbr": "LA"
    }, {
        "task_id": "Workflow_A_Task_2",
        "task_name": "Planning A",
        "task_abbr": "PA"
    },{
        "task_id": "Workflow_A_Task_3",
        "task_name": "Checking A",
        "task_abbr": "CA"
    },{
        "task_id": "Workflow_A_Task_4",
        "task_name": "Review A",
        "task_abbr": "RA"
    }]
}

I need to iterate over each of the objects in staff_comp_array and modify the array such that the result will be as follows:

[{
    "staff_id": "CEB",
    "competency": [{
        "workflow": "Workflow A",
        "task_competency": [{
        "task_id": "Workflow_A_Task_1",
        "task_name": "Loading A",
        "task_abbr": "LA"
     },{
        "task_id": "Workflow_A_Task_2",
        "task_name": "Planning A",
        "task_abbr": "PA"
    }]
    }, {
        "workflow": "Workflow B",
        "task_competency": [{
        "task_id": "Workflow_B_Task_1",
        "task_name": "Loading B",
        "task_abbr": "LB"
    },{
        "task_id": "Workflow_B_Task_2",
        "task_name": "Planning B",
        "task_abbr": "PB"
    }]
    }]
},
{
    "staff_id": "XD",
    "competency": [{
        "workflow": "Workflow A",
        "task_competency": [{
        "task_id": "Workflow_A_Task_3",
        "task_name": "Checking A",
        "task_abbr": "CA"
    }]
    }, {
        "workflow": "Workflow B",
        "task_competency": [{
        "task_id": "Workflow_B_Task_2",
        "task_name": "Planning B",
        "task_abbr": "PB"
    }, {
        "task_id": "Workflow_B_Task_3",
        "task_name": "Checking B",
        "task_abbr": "CB"
    }]
    }]
}
]

Sails is used to access the MongoDB.

staff_comp_array is a long list with around 100 staff. I need to do achieve my above expected output properly. How do I do achieve this with javascript?

fn: async function () {
let staff_comp_array = await StaffCompetency.find({});
staff_comp_array.forEach(function(item){ 
          let temp_competency_list = [];
          item.competency.forEach(function(comp){
              let temp_competency = {};
              let tasks = [];
              let workflow_res = await Workflows.findOne({workflow: comp.workflow});
              comp.task_competency.forEach(function(task){
                tasks.push(workflow_res.tasks.filter(obj => obj.task_id === task)[0]);
              });
              temp_competency['workflow'] = comp.workflow;
              temp_competency['task_competency'] = tasks;
              temp_competency_list.push(temp_competency);
        });
        item.competency = temp_competency_list;
});
return staff_comp_array;
}

Any help would be appreciated!

Thanks

Getting object data from API and then displaying it (React Fetch)

I’m trying to extract the data from this API https://fe-assignment.vaimo.net/ to render the object name. It should be a drone sale item but I cant display it on mapping or such.

I only have to extract this items data and there are no other objects or such in the API. I want to eventually display the product with its image, and all its attributes but I am just trying to extract simple strings from the JSON like the product name.

The result of the above code when ran is simply the heading with no further content. Both console logs return the API data in full. See ComponentDidMount and render

import { render } from "@testing-library/react"
import React from "react"
import "./App.css"
import {useState, useEffect } from 'react'
import axios from 'axios'
import Colors from "./components/Colors"
import DetailsThumb from "./components/DetailsThumb"

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      items: [],
      isLoaded: false,
    };
  }

  

  componentDidMount() {
    fetch("https://fe-assignment.vaimo.net/")
      .then((res) => res.json())
      .then(data => { console.log(data)
        this.setState({
          isLoaded: true,
          items: data,
        });
      });
  }

  render() {
    let content = null
    var { isLoaded, items } = this.state;
    if (!isLoaded) {
      return <div>Loading..</div>;
    } else {
      console.log(items)
      if (items.data){
        content = items.map((product, key) => <div>{product.name}</div>)
      }
      return (
        <div>
          <h1>The drone page</h1>
          {content}
          </div>
      );
    }
  }
}

export default App;

How to realize … /> in a react-router-dom v6?

I have a modal which depended on a url.

[my modal in jsx][1]    <ModalWindow
                                modalVisible={Boolean(match)}
                                onCloseWindow={this.onCloseWindow}
                                modalContent={modal}
                            />
                        )
                    }}
                />

I am getting an error <A is only ever to be used as the child of element, never rendered directly. Please wrap your in a .>

But i already wrapped all my app in a tag.

export default function AppRouter() {
return (
    <Routes>
        <Route 
            path={"/home"}
            element={<HomeApp />}
        />
        <Route 
            path={"/preview/:id"}
            exact
            element={<HomeApp />}
        />
         <Route
            path={"/fullInfo/:id"}
            exact
            element={<HomeApp />}
         />
        <Route
            path={"*"}
            render={<Navigate to="/home"/>}
        />
    </Routes>
)

}

P.s I am new in a react-router-dom of the new version..