In javascript how can we return data inside of a try catch [duplicate]

I have sqlite database and I am trying to return data from the variable named results. Currently I get undefined. Not sure how to return value from try catch

const checkEntry = async (activeProfile, item) => {
    try {
      return await db.transaction(async tx => {
        return await tx.executeSql(
          'SELECT * FROM MidiMap WHERE profileId="' + activeProfile + '"',
          [],
          (sqlTx, res) => {
            console.log('Scene check data retrieved successfully');
            let len = res.rows.length;

            if (len > 0) {
              let results = [];
              for (let i = 0; i < len; i++) {
                let item = res.rows.item(i);
                results.push({id: item.id, name: item.name});
              }
              // Need to return the data from results
              return results;
            }
          },
          error => {
            console.log('error on getting midi mapping ' + error.message);
          },
        );
      });
    } catch (error) {
      console.error(error);
    }
  };

I am calling the function like this however I get undefined

checkEntry().then((r)=>{
  console.log(r)
})

MomentJS – Showing the wrong time for Pacific Timezone

I did not write the code involving Moment. But I’m tying to convert it to plain JavaScript.

moment.tz.add("America/Los_Angeles|PST PDT PWT PPT|80 70 70 70|010102301010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-261q0 1nX0 11B0 1nX0 SgN0 8x10 iy0 5Wp1 1VaX 3dA0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1a00 1fA0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 s10 1Vz0 LB0 1BX0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0|15e6");
console.log('Central Time: ', moment()._d.toString());
console.log('Pacific Time: ', moment().tz("America/Los_Angeles")._d.toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.4/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone.min.js"></script>

I live in the Central Time Zone. As you can see above, MomentJS returns the correct time for the Central Timezone.

However, when I try to get the time in the Pacific Time Zone, it is 5 hours off. I suspect it has to do with the GMT difference, as shown here.

GMT-0500 (Central Daylight Time)

I have looked through the documentation and studied this extensively but cannot figure out why the time is 5 hours off.

Regex Match phrases with or without quotation

im new to regular expressions and i want to build an expression that finds the below pattern:

We have the string:

"'Hello world',dude, 'Somethings, never, turn and go', bye" 

I want a regular expression that gives this result:

['Hello world',dude,'Somethings, never, turn and go',bye]

I tried this (‘s*,s*’) but doesnt work.

Regex to extract LHS and RHS of a char

I am looking for a Regex for the below problem –

String – "32 - This-may-contain - hypen-as-well"

Divide from "-"

Result -> "32 ", " This-may-contain - hypen-as-well"

I was doing "32 - This-may-contain-hypen-as-well".split("-"); but the RHS can also contain hypens and I need to do more operations to join back the rhs with hypen.

vue.js get id from select to axios post and display another select

Probably this is a very stupid question, i’m new in vue.js and javascript, so please forgive me if the question is not properly explained or the answer is simple… I have a problem
I wanted to get the id from one select, and put that id into the other api and display the models in the next select, the listings work beautifully as I do the rigid.
But I don’t know how to pass/paste the id into the async mounted axios function “api/sd/model/get”, id)”

This is my template

   
  <main class="home-page">
   
       <select v-model="selectedMark">
        <option v-for="model in items" :key="model.id">{{ model.name.value  }}</option>
      </select><br><br>

        <select v-model="selectedModel">
        <option v-for="make in info" :key="make.id" >{{ make.name.value }}</option>
      </select><br><br>

      
        <button type="submit" class="conectButton">Połącz</button>
      <div class="titleCarMain"><p class="titleCar">{{selectedMark}}</p><p class="titleComponent">{{selectedModel}}</p></div>
    
     
  
     </main>

And this is script

import axios from 'axios';

export default {
  name: "App",
  data() {
      return {
      
      
      info: null,
      items: [],
      selectedMark: null,
      selectedModel: null,

      };
  },
  
  async mounted() {
   axios
     .get("http://local/api/sd/make/get")
     .then(response => { this.items = response.data.data.items });
    

    const id = { id: this.selectedMark }  //dont work 
     
    await axios
     .post("http://local/api/sd/model/get", id) //dont work 
     .then(response => { this.info = response.data.data.items });

   },
   
  
};

Any good soul who can help this newbie? (if can explain the why of the solution as well, for understand, will be amazing!!)

Thanks in advance!!

Paint numbers with Javascript [closed]

I didn’t find anything related on the internet.

I need a javascript code that returns me the green or red color according to the number.

But I don’t want it to be static, for example the more negative the redder it gets. And the more positive, the greener it gets.

-1 and 1 would have light colors for example, 1000 and -1000 would be stronger. Similar to what is done in excel and Google Spreadsheet.

Dropdown list for currency converter

When creating a currency converter, there was a problem, because I did it through a select, but it turned out that I needed through a drop-down list, how can I implement such a drop-down list https://prnt.sc/MhHMEPRS089F or similar, but not to change my js code too much, is this possible? Please help, thanks in advance.

const currencyOne = document.getElementById('currency-one');
const currencyTwo = document.getElementById('currency-two');
const amountOne = document.getElementById('amount-one');
const amountTwo = document.getElementById('amount-two');
const rates = document.getElementById('rate');
const swap = document.getElementById('swap');

// Fetch exchange rates and update the dome
function converter() {
  const currency_one = currencyOne.value;
  const currency_two = currencyTwo.value;

  fetch(`https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json`)
    .then((res) => res.json())
    .then((data) => {  
    
    data.unshift({txt:"Гривня", rate:1, cc:"UAH"})
            
      currency1 = data.find(item => item.cc === currency_one);
      currency2 = data.find(item => item.cc === currency_two);
      //console.log(c1,c2);
      rates.innerText =  `1 ${currency_one} = ${(1 * currency1.rate / currency2.rate).toFixed(4)} ${currency_two}`;
      amountTwo.value = (amountOne.value !== '') ? (amountOne.value * currency1.rate / currency2.rate).toFixed(2) : '';
      
    });
}

converter();

// Event Listeners
currencyOne.addEventListener('change', converter);
amountOne.addEventListener('input', converter);
currencyTwo.addEventListener('change', converter);
amountTwo.addEventListener('input', converter);

swap.addEventListener('click', () => {
  const temp = currencyOne.value;
  currencyOne.value = currencyTwo.value;
  currencyTwo.value = temp;
  converter();
});
:root {
  --primary-color: #5fbaa7;
}

* {
  box-sizing: border-box;
}

body {
  background-color: #f4f4f4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  margin: 0;
  padding: 20px;
}

.header {
  display: flex;
  align-items: center;
}

.indent-right {
  display: flex; 
  width: 24px; 
  height: 24px; 
  background-image: url("https://cdn.privat24.ua/icons/file/ServiceCurrency.svg"); 
  background-repeat: no-repeat; 
  background-position: center center; 
  background-size: contain;
  margin-right: 10px !important;
}

b {
  font-weight: var(--tw-semi);
}

.btn {
  display: inline-flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  position: relative;
  width: 57px;
  height: 44px;
  font-size: 16px;
  line-height: 1.5;
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 4px;
  transition-duration: 450ms;
  transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
  word-break: normal;
  color: rgba(0, 0, 0, 0.54);
  background: rgb(255, 255, 255);
  box-shadow: rgb(0 0 0 / 12%) 0px 2px 4px 0px, rgb(0 0 0 / 12%) 0px 0px 4px 0px;
  white-space: nowrap;
  border-style: none;
  border-width: 0px;
  border-color: rgb(255, 255, 255);
  margin: 0px;
  cursor: pointer;
}

.btn:hover {
  background-color: lightgrey;
}

.swap-rate-container .btn-arrows {
  transform: rotate(90deg);
  opacity: 0.54;
  transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1);
  position:absolute;
  font-family: 'Open Sans', sans-serif;
}


.currency {
  padding: 40px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.currency select {
  padding: 10px 50px 10px 10px;
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
  font-size: 16px;
  background: transparent;
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%20000002%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
  background-position: right 10px top 50%, 0, 0;
  background-size: 12px auto, 100%;
  background-repeat: no-repeat;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.currency select:hover {
    border-bottom: 1px solid rgba(0, 0, 0, 0.54);
}

.currency select:focus {
  border-color: #8dc641;;
}

select {
  outline: 0;
  border: none;
}

.select-selected {
  
}

.select-items {
  background-color: #5fbaa7;
}

option[value=USD] {
    border-radius: 2px;
    display: flex; 
    width: 18px; 
    height: 15px; 
    background-image: url("https://cdn.privat24.ua/icons/file/US.svg"); 
    background-repeat: no-repeat; 
    background-position: center center; 
    background-size: contain;
}

input::placeholder {
  font-family: 'Open Sans', sans-serif;
  
}
.currency input {
  background: transparent;
  font-size: 20px;
  line-height: 1.5;
  text-align: right;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.87);
  border-style: none;
  border-width: 0px;
  border-radius: 0px;
  background: transparent;
  box-shadow: none;
  outline: none;
  width: 68%;
  font-family: 'Open Sans', sans-serif;
  background: transparent;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  margin-top: 4px;
}

.currency input:hover {
  display:block;
  line-height: 1.5;
  font-family: "Open Sans", sans-serif;
  border-bottom: 1px solid rgba(0, 0, 0, 0.54);
}

.currency input:focus {
  border-color: #8dc641;
}

.currency-select {
  position: relative;
  width: 100px;
}

/* .currency input::after {
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}

.currency input::before {
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}

.currency input:hover::after {
  transform: scaleX(1);
}

.currency input:hover::before {
  transform: scaleX(1);
} */

.select-placeholder {
  background: rgb(255, 255, 255);
  color: rgba(0, 0, 0, 0.38);
}

.swap-rate-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rate {
  color: black;
  font-size: 15px;
  padding: 0 10px;
  background: #E0E0E0;
  line-height: var(--tl-small);
  padding: 8px;
  font-family: 'Open Sans', sans-serif;
  border-radius: 2px;
}

input::-webkit-inner-spin-button {
  display: none !important;
}

@media (maz-width: 600px) {
  .currency input {
    width: 200px;
  }
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Currency Converter</title>
    <link rel="shortcut icon" href="img/currencies-icon-10.jpg" type="image/x-icon">
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="container">
      <div class="header">
        <div class="indent-right"></div>
        <b>Конвертер валют</b>
      </div>
      <div class="currency">
        <select id="currency-one">
          <option value="EUR">EUR</option>
          <option value="USD" selected>USD</option>       
          <option value="GBP">GBP</option>
          <option value="UAH">UAH</option>
        </select>
        <input type="number" id="amount-one" placeholder="200" />
      </div>

      <div class="swap-rate-container">
        <button class="btn" id="swap">
        <div class="btn-arrows">
        <div style="display: flex;">
          <svg
            height="24px"
            width="24px"
            version="1.1"
            viewBox="0 0 24 24"
            xmlns="http://www.w3.org/2000/svg"
          >
            <g
              fill="none"
              fill-rule="evenodd"
              stroke="none"
              stroke-width="1"
            >
              <path d="M0 0h24v24H0z"></path>
              <path
                d="M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"
                fill="#000"
                fill-rule="nonzero"
              ></path>
            </g>
          </svg>
        </div>
      </div>
    </button>
        <div class="rate" id="rate"></div>
      </div>
      <div class="currency">
        <select id="currency-two">
          <option value="UAH" selected>UAH</option>
          <option value="GBP">GBP</option>
          <option value="EUR">EUR</option>
          <option value="USD">USD</option>
        </select>
        <input type="number" id="amount-two" placeholder="200" />
      </div>
    </div>
    <script src="script.js"></script>
  </body>
</html>

What can i do if a json object has a # on one of its futures tag area [duplicate]

I was trying to get data from lastfm api. I was fethcing to userinfo callback but it returns profile picture like:

"image": 
[
{,
  {
    "size":"extralarge",
"#text":"https://lastfm.freetls.fastly.net/blablablabla.png"
  }
]

as you see picture tag has # on it so when i want to reference to image as

<img src = data.images[3].#text ></img>

is giving syntax error. So any of you can help me ?

Google Maps JS Polygon autoclose

I’m trying to draw polygons on google maps with JS.

This is my code :

function initialize() {
        
    var bounds = new google.maps.LatLngBounds();

    map = new google.maps.Map(
    document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(40.5243851,17.418682),
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.HYBRID
    });

    var drawingManager = new google.maps.drawing.DrawingManager({
        drawingMode: google.maps.drawing.OverlayType.POLYGON,
        drawingControl: true,
        drawingControlOptions: {
            position: google.maps.ControlPosition.BOTTOM_CENTER,
            drawingModes: [
            google.maps.drawing.OverlayType.POLYGON]
        },
        markerOptions: {
            icon: 'images/car-icon.png'
        },
        polygonOptions: {
            fillColor: '#BCDCF9',
            fillOpacity: 0.8,
            strokeWeight: 2,
            strokeColor: 'red',
            clickable: false,
            editable: true,
            zIndex: 1
        }
    });

    drawingManager.setMap(map)



    google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {

     // code here

    });

}

This works pretty well but i have to close the polygon (the first corner should be the same as the last corner) to trigger ‘polygoncomplete’.

Is there a way to draw a closed polygon just by adding 3 corners ?

Thanks

Is it possible to create a websocket connection somehow from an HTTPS-origin javascript webpage to another cross-origin WS server?

I am developing a websocket server (let’s call it WS), which is totally independent from another HTTPS server which I am also developing (let’s call it Main).

WS itself is working well and I also have a command line testing tool which is written in Node.JS that can communicate with WS via websocket messages.

Main itself is also working well and I can open web pages with browsers via HTTPS without any problem.

Here’s the problem:

Since command-line testing is not user-friendly to engineers that are not familiar with command lines, I want to create a “Browser Webpage Testing Tool” on Main in order to send messages to WS and receive response.

I basically used codes from here: https://blog.teamtreehouse.com/an-introduction-to-websockets#:~:text=To%20send%20a%20message%20through,binary%20data%20through%20a%20WebSocket.

However on this line

// Create a new WebSocket.
var socket = new WebSocket('ws://Ws-address');

The browser tells me “The page at ‘https://MainUrl/testing-tool’ was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint ‘ws://Ws-address/’. This request has been blocked; this endpoint must be available over WSS.”

However the WS server is a real time application and is not intended to work over wss, rather as a requirement it must be optimized in speed as much as possible and anything else must be sacrificed.

Therefore WS will use plain ws instead of wss which has an additional tls handshake.

Is there any way to make my “Testing Tool” work?

‘this’ implicitly has type ‘any’ because it does not have a type annotation when using function in function

I have a function A and would like to use function B in A.

public getPrice(machine: Machine): number {
  if(machine.ok) {
    return this.prices[machine.articleNo];
  }
}

public sumField(): number {
  let sum: number = 0;

  this.stationMachines.forEach(function (machine: Machine) {
    sum += this.getPrice(machine);
  });
  return sum;
}

the “‘this’ implicitly has type ‘any’ because it does not have a type annotation” errorr occurs when trying to use the getPrice() function.

Can an element be hidden and shown without Javascript?

I’m working on an app where I am using the DOMTokenList for shown and hidden an element using add() and remove() methods but the code is getting big. Example:

button.addEventListener("click", () => {
   elem1.classList.add("display-none");
   elem2.classList.remove("display-none");
   elem3.classList.remove("display-none");
   elem4.classList.add("display-none");
});

button2.addEventListener("click", () => {
   elem1.classList.remove("display-none");
   elem2.classList.add("display-none");
   elem3.classList.add("display-none");
   elem4.classList.remove("display-none");
});

I’ve seven code parts similar to the example and I started looking others ways but I tried with CSS

.box {
    --displayRed: block;
    --displayGreen: none;
    --displayBlue: none;
    height: 100px;
    width: 100px;
}

.box--red { 
    display: var(--displayRed);
    background-color: #ff0000;
}

.box--green { 
    display: var(--displayGreen);
    background-color: #00ff00;
}

.box--blue { 
    display: var(--displayBlue);
    background-color: #0000ff;
}

.box--red:target {
  --displayRed: block;
  --displayGreen: none;
  --displayBlue: none;
}

.box--green:target {
  --displayRed: none;
  --displayGreen: block;
  --displayBlue: none;
}

.box--blue:target {
  --displayRed: none;
  --displayGreen: none;
  --displayBlue: block;
}
<div>
    <div class="box">
        <div id="boxRed" class="box box--red"></div>
        <div id="boxGreen" class="box box--green"></div>
        <div id="boxBlue" class="box box--blue"></div>
    </div>
    
    <nav>
      <ul>
        <li><a href="#boxRed">Show red box</a></li>
        <li><a href="#boxGreen">Show green box</a></li>
        <li><a href="#boxBlue">Show blue box</a></li>
      </ul>
    </nav>
</div>

I was expecting the red box to hide when I clicked the link to show the yellow box but it only scrolled down and didn’t hide the red box. I tried to find others solution with videos, Pseudo-classes, Selectors, even with two question that are Can text be hidden and shown using just CSS (no JavaScript code)? [closed] and Ocultar y Mostrar un elemento css but I can’t find the perfect idea. I ACCEPT SUGGESTIONS

Vue 3 with Composition API: Update Parent Component DOM based on custom method emitted from Child component Update Lifecycle Hook

I’m doing a chat widget (a tab system where I have multiple tabs, each tab being a chat) and I’m trying to paint some sort of UX notification every time the user gets a new message from the backend (enduser). In order to do that what I’m trying to do is to emit a custom method from my child component onUpdate lifecycle hook that will trigger the parent component event that will add a class to my parent component in order to add a red border every time the final user send a new message.

This is my child component:

<template>
  <div class="flex-col flex-nowrap">
    <BaseTranslationBar />
    <div id="chat-body" ref="chatBody" class="overflow-y-auto p-2">
      <ul id="chatBox" class="mt-4">
        <BaseChatMessage
          v-for="(chatMessage, index) in chatSession.events"
          :chatMessage="chatMessage"
          :key="index"
          :chatSession="chatSession"
          :class="{ 'mt-0': index === 0, 'mt-4': index > 0 }"
        />
      </ul>
    </div>
    <form @submit.prevent="sendMessage" class="chat-form relative mt-6">
      <textarea
        class="chat-textarea h-[160px] py-4"
        placeholder="Add your message here..."
        type="text"
        v-model="message"
      />
      <div
        class="chat-input-buttons flex justify-end absolute bottom-0 right-0 pb-4"
      >
        <button
          class="flex flex-col justify-center focus:outline-none focus:ring"
        >
          <i class="chat-input-button fa-paperclip fas text-blue-500"></i>
        </button>
        <button
          type="submit"
          value="Send"
          class="flex flex-col justify-center focus:outline-none focus:ring"
        >
          <i class="chat-input-button fa-paper-plane fas text-blue-500"></i>
        </button>
      </div>
    </form>
    <BasePythiaBar class="mt-4" />
    <BaseChatButtonRow :chatId="chatSession.id" class="mt-4" />
  </div>
</template>

<script>
import { ref, onMounted, onUpdated } from "vue";
import ChatService from "@/services/ChatService.js";
import BaseChatMessage from "@/components/BaseChatMessage.vue";
import BaseTranslationBar from "@/components/BaseTranslationBar.vue";
import BasePythiaBar from "@/components/BasePythiaBar.vue";
import BaseChatButtonRow from "@/components/BaseChatButtonRow.vue";
export default {
  emits: ["emittingChatTabUxState"],
  components: {
    BaseChatMessage,
    BaseChatButtonRow,
    BasePythiaBar,
    BaseTranslationBar,
  },
  props: {
    chatSession: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  setup(props, { emit }) {
    const message = ref("");
    const chatBody = ref(null);
    onMounted(() => {
      scrollChatBodyToEnd();
    });
    onUpdated(() => {
      scrollChatBodyToEnd();
      submitChatTabUxState();
    });
    const scrollChatBodyToEnd = () => {
      if (chatBody.value) {
        chatBody.value.scrollTop = chatBody.value.scrollHeight;
      }
    };
    const submitChatTabUxState = () => {
      emit("emittingChatTabUxState");
    };
    const sendMessage = () => {
      const messageObject = {
        aggregateId: props.chatSession.id,
        message: message.value,
        agentId: props.chatSession.agentId,
        skippedValidationErrors: [],
      };
      ChatService.sendChatMessage(messageObject);
      message.value = "";
    };
    return {
      message,
      sendMessage,
      chatBody,
      scrollChatBodyToEnd,
      submitChatTabUxState,
    };
  },
};
</script>

As you can see everytime the dom of this component gets updated I’m emitting a custom event called “submitChatTabUxState” to the parent.

This is the parent component:

<template>
  <div>
    <ul
      class="tag-menu flex space-x-2"
      :class="defaultTagMenu ? 'default' : 'historic'"
      role="tablist"
      aria-label="Tabs Menu"
      v-if="tabTitles && tabTitles.length"
    >
      <li
        @click.stop.prevent="selectedTitle = title"
        v-for="title in tabTitles"
        :key="title"
        :title="title"
        role="presentation"
        :class="{ selected: title === selectedTitle }"
      >
        <a href="#" role="tab" :class="updateChatClassValue" 
        @emittingChatTabUxState="updateChatClass()">
          {{ title }}
        </a>
      </li>
    </ul>
    <slot />
  </div>
</template>

<script>
import {
  ref,
  computed,
  useSlots,
  provide,
  watch,
  onMounted,
  onUpdate,
} from "vue";
export default {
  props: {
    defaultTagMenu: {
      type: Boolean,
      default: true,
    },
  },
  setup() {
    const updateChatClassValue = ref("");
    const slots = useSlots();
    const tabTitles = computed(() =>
      slots.default()[0].children.map((tab) => tab.props.title)
    );
    const tabTitlesLength = computed(() => tabTitles.value.length);
    let selectedTitle = ref(tabTitles.value[0]);
    provide("selectedTitle", selectedTitle);
    provide("tabTitles", tabTitles);
    watch(tabTitlesLength, (currentValue, oldValue) => {
      if (currentValue < oldValue) {
        selectedTitle.value = tabTitles.value[0];
      }
    });
    onMounted(() => {
      updateChatClass();
      timing();
    });
    onUpdate(() => {
      console.log("updating parent component");
    });
    const timing = () => {
      setInterval(() => {
        updateChatClassValue.value = "";
      }, 2000);
    };
    const updateChatClass = () => {
      console.log("Updating chat class");
      updateChatClassValue.value = "chatUpdated";
    };
    return {
      tabTitles,
      selectedTitle,
      tabTitlesLength,
      timing,
      updateChatClass,
      updateChatClassValue,
    };
  },
};
</script>

Now what is confusing to me at this point is where to trigger the emitted event coming from my child component in the parent component. I don’t have a specific call to action to do this because I will need to trigger the custom event in my parent component every time the child component gets updated so I don’t know where should I place something like @emittingChatTabUxState=”updateChatClass()”. I’m adding it at the <a> tag at the moment but it’s not working.