Class Reactivity with Proxy does not work as expected in Vue 3

I have a Class with a proxy-based object, the set() method changes another property of the same class, everything works fine if I run the code only in JS/TS.

class Form {
  errors = []
  values = {}

  constructor(values) {
    this.values = new Proxy(values, {
      set: (target, prop, value) => {
        target[prop] = value

        this.errors.push('test')

        return true
      },
    })
  }
}

const form = new Form({
  name: 'Jhon',
  age: 20,
})

form.values.name = 'Maria'
form.values.age = 30

console.log(form.errors)

Expected result of form.errors is an Array like ['test', 'test']

But if I run it inside Vue, using {{ form.errors }} inside <template> it’s not reactive, it’s not updated in real time.

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/vue@3"></script>
  </head>
  <body>
    <script src="https://unpkg.com/vue@3"></script>

    <div id="app">{{ form.errors }}</div>

    <script>
      class Form {
        errors = []
        values = {}

        constructor(values) {
          this.values = new Proxy(values, {
            set: (target, prop, value) => {
              target[prop] = value

              this.errors.push('test')

              return true
            },
          })
        }
      }

      const app = Vue.createApp({
        data() {
          return {
            form: new Form({
              name: 'Jhon',
              age: 20,
            }),
          }
        },
        mounted() {
          this.form.values.name = 'Maria'
          this.form.values.age = 30
        },
      })

      app.mount('#app')
    </script>
  </body>
</html>

form.errors is updated, but this does not reflect in Vue, it is as if Vue cannot observe these changes, the proof of this is that if we do

mounted() {
  this.form.values.name = 'Maria'
  this.form.values.age = 30

  this.form.errors.push('hello')
}

we will have the expected result in the DOM

['test', 'test', 'hello']

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/vue@3"></script>
  </head>
  <body>
    <script src="https://unpkg.com/vue@3"></script>

    <div id="app">{{ form.errors }}</div>

    <script>
      class Form {
        errors = []
        values = {}

        constructor(values) {
          this.values = new Proxy(values, {
            set: (target, prop, value) => {
              target[prop] = value

              this.errors.push('test')

              return true
            },
          })
        }
      }

      const app = Vue.createApp({
        data() {
          return {
            form: new Form({
              name: 'Jhon',
              age: 20,
            }),
          }
        },
        mounted() {
          this.form.values.name = 'Maria'
          this.form.values.age = 30

          this.form.errors.push('okay')
        },
      })

      app.mount('#app')
    </script>
  </body>
</html>

Could anyone help me solve this problem or make this work?

What I want is for form.errors to be reactive in Vue just like any other property.

How to get the sum of number instead of typing them next to each other on JavaScript?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        function getTotal() {

            var num1 = document.getElementById("num1").value;
            var num2 = document.getElementById("num2").value;
            var num3 = document.getElementById("num3").value;
            var total = num1 + num2 + num3;
            document.getElementById("result").innerText = total
        }
    </script>
</head>
<body>
   
    <form>
        <label>Number 1:</label>
        <input type="text" id="num1" />
        <br />

        <label>Number 2:</label>
        <input type="text" id="num2" />
        <br />

        <label>Number 3:</label>
        <input type="text" id="num3" />
        <br />
        <br />
        <input type="button" value="Add numbers" 
               onclick="getTotal();"/>
<h2 id="result"></h2>        
    </form>
</body>
</html>

I want to put numbers in three different boxes then it adds them up all
and gives me an answer. Instead it puts all the number next to each other.
I am using Html and Javascript.

How to change values in nested array of objects in ReactJS?

I have an object like this:

const obj = [{id: "1", obj_of_names: [{
                             id: "a1",
                             name: "abc",
                             school: "xyz" },
                            { id:"b1",
                             name: "def",
                             school: "zyx" },
                            { id:"c1",
                             name: "ghi",
                             school: "pqr" }]
             },
             {id: "2", obj_of_names: [{
                             id: "d1",
                             name: "abc123",
                             school: "xyz123" }]
             }]

I want to modify school from pqr to pqr123. I tried the useState hook, but I am only getting this

                            {
                             id:"c1",
                             name: "ghi",
                             school: "pqr123"
                            }

as output, how can solve this?

Shorten for-loops into one

let board_coord = []

for (let i = 0; i < 3; i++) {
    board_coord.push(
        {
            x: i*166, y: 0
        }
    )
}
for (let j = 0; j < 3; j++) {
    board_coord.push(
        {
            x: j*166, y: 166
        }
    )
}
for (let k = 0; k < 3; k++) {
    board_coord.push( 
        {
            x: k*166, y: 332
        }
    )
}

is it possible to shorten these three for loops into one
the code works absolutely fine, I just want to know if there is a possibility to shorten these three for loops into one for exercising reasons and also for code-readability

Repair increment data in array (js)

I am trying to correct the incremented value in the data I received. It looks more or less like this:

const data = [1,2,4,5,6,7];
const correctResult = [1,2,3,4,5,6];

What I would like to get is rightly incremented values + 1 but so as to preserve the possible indexes.

I wrote such a function but it is not efficient:

data.map((item, index, array) => {
    if (item === array[index + 1] - 1) {
        return;   
    }

    array[index + 1] = array[index + 1] - 1;
});

The programming code is javascript. I would like to write a good code to be a good model for me.

A middleman server between my device and a third party website?

I want to make a request from my website to my own server, the server would further request a third party website, it would run the website through an extension (as if the request was made by you on a browser with an extension) and other various content filters, maybe even rendering the website on the server, before serving it and rendering it on my website.

Since this is for Safari on iOS the extension and filtering must happen on the server and client side is not possible, I think I could do this with Python and Selenium but seems like a very bad way of doing it. It will be only for personal use so I am not worried about any external issues.

Is this at all feasible and if yes I would appreciate some pointers in the right direction

Uncaught Error: Workbook is empty in xlsx and alasql excel file export

I’m using XLSX and alasql to export json object in to excel getting workbook is empty error, how to resolve

import * as alasql from 'alasql'
import * as XLSX from 'xlsx'

alasql.utils.isBrowserify = false
alasql.utils.global.XLSX = XLSX


const fileName = 'Ticket Details ' + props.ticketNumber
alasql('SELECT INTO XLSX("' + fileName + '.xlsx",?) FROM ?', [opts, finalData])

I am trying to write an XML file as a table on a HTML page inside a div with id “div1” but I cant get the table to appear on the page

So I am trying to write an XML file as a table on a HTML page inside a div with id “div1” but I cant get the table to appear on the page and I am stuck. It doesnt have to necessarily be inside a div but it has to appear as HTML table on page.. I am new to javascript and struggling to find a solution but there are very few similar examples online so I hope someone can help…

This is the HTML page….

<!DOCTYPE html>
<html>
    <head>
        <title>kol2</title>
    </head>

    <body>

        <div id="div1"></div>    
        <script src="kol2.js"></script>
    </body>

    
    
</html>

Here is the XML file…

<?xml version="1.0"?>
<nekretnine xmlns:h="http://www.nekretnine.hr">
    <h:nekretnina>
        <h:ID>1211</h:ID>
        <h:Adresa>Vukovarska 121</h:Adresa>
        <h:Grad>Zagreb</h:Grad>
        <h:Tip>Stan</h:Tip>
    </h:nekretnina>
    <h:nekretnina>
        <h:ID>2123</h:ID>
        <h:Adresa>Horvatova 13</h:Adresa>
        <h:Grad>Biograd</h:Grad>
        <h:Tip>Kuća</h:Tip>
    </h:nekretnina>
</nekretnine>

And here is the javascript code I have so far..

if (window.XMLHttpRequest)  
xmlhttp=new XMLHttpRequest();

xmlhttp.open("GET","nekretnine.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("nekretnina");

for (i=0;i<x.length;i++)
{
    
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ID")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("Adresa")[0].childNodes[0].nodeValue);document.write("</td><td>");
document.write(x[i].getElementsByTagName("Grad")[0].childNodes[0].nodeValue);document.write("</td><td>");
document.write(x[i].getElementsByTagName("Tip")[0].childNodes[0].nodeValue); document.write("</td></tr>");

}

document.write("</table>");

Is there a way in NodeJS to create global variables that live only for the lifetime of the request? [duplicate]

I’m creating an API using Express, and I wanna know if there is a way to create a global variable (something like a global store) that only keeps data for the duration of the request.

I understand that because NodeJS handles all requests in the same thread, any global variable I create will persist across requests. So I wonder if there’s a clean way to achieve what I want to.

Does NodeJS or Express provide a way where I could clean up this global state at the end of each request? Like an event or something similar. Or is there a package that already does this?

Maybe I could get way leveraging closures, but I’m looking for something more flexible.

I am new at react and am trying to build an app

I am new at react and am trying to build an app. I used the figure tag in the component and a still cannot make changes on the css or see the component in inspect element of chrome. Here are the codes.

my code

index.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Main from './Components/Main'
import './styles/stylesheet.css'



ReactDOM.render(<Main/>, document.getElementById('root'));

ReactDOM.render(, document.getElementById(‘root’));

Main.js

enter code here
import React, { Component } from 'react'
import Title from './Title'
import Photowall from './Photowall'
const posts = [{
id: "0",
description: "beautiful landscape",
imageLink: "https://image.jimcdn.com/app/cms/image/transf/none/path/sa6549607c78f5c11   /image/i4eeacaa2dbf12d6d/version/1490299332/most-beautiful-landscapes-in-europe-lofoten-european-best-destinations-copyright-iakov-kalinin.jpg" +
"3919321_1443393332_n.jpg"
}, {
id: "1",
description: "Aliens???",
imageLink: "https://s3.india.com/wp-content/uploads/2017/12/rocket.jpg"
}, {
id: "2",
description: "On a vacation!",
imageLink: "https://fm.cnbc.com/applications/cnbc.com/resources/img/editorial/2017/08/24/104670887-VacationExplainsTHUMBWEB.1910x1000.jpg"
}]
class Main extends Component{
render(){
    return <div>
              <Title title={'Photowall'}/>
              <Photowall posts={posts}/>
            </div>
}

}
export default Main

Photowall.js

enter code here
import React,{ Component} from 'react'
import Photo from './Photo'
class Photowall extends Component{
render() {
    return
    
        <div className='photo-grid'>
            {this.props.posts.map((post,index)=> <Photo key={index} post={post}/>)}
        </div>
    
  }
}
export default Photowall

Photo.js

enter code here

import React, {Component} from "react";

class Photo extends Component{
render(){
const post =this.props.post
return <figure className="figure"></figure>

}
}
export default Photo

Stylesheet.js

enter code here

html{
font-size: 10px;
}
h1{
font-family: billabong;
text-align: center;
font-size: 13rem;
margin: 2rem 0rem;
font-weight: 400;
letter-spacing: 4px;
color: grey;
}

@font-face {
font-family: billabong;
src: url('https://fonts.cdnfonts.com/s/13949/Billabong.woff') format('woff');
}
.photo-grid {
max-width: 1000px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
} 

.figure {
flex-basis: calc (33.333%-4rem);
border: 1px solid #d3d3d3;
padding: 2rem;
flex-grow: 1;
margin: 0 2rem;   
}

Next.js Variables reset after i switch pages

Im trying to simply have a shared variable between my pages in my Next.Js application.. My _app.js below contains the following..


import { useState } from 'react';

const CustomApp = ({ Component, pageProps }) => {

  // Variables
  const [testVariable, setTestVariable] = useState(0)

  // globalFunctions
  const setTestVariable = (newValue) => setLocalVariable(newValue);


  return (
    <Component 
      {...pageProps}
      // Export Variables
      testVariable={testVariable}
      // Export Functions
      setTestVariable={setTestVariable}

    />
  );
}

export default CustomApp

I have two pages… Both are the same except one is called index.js and exports Home, the other is called about.js and exports About…

import { useState, useEffect } from 'react'
import 'bulma/css/bulma.css'
import styles from '../styles/Home.module.css'

const Home = ({ testVariable, setTestVariable, }) => {

 
  useEffect(() => {

  })

  
  return (
    <div id={styles.outerDiv}>
      <Head>
        <title>My Next.Js Page</title>
        <meta name="description" content="A Next.js application" />
      </Head>

      <div id={styles.navBar}>
        <a href="/" id={styles.navLink}>
          <h3>Home</h3>
        </a>
        <a href="/about.js" id={styles.navLink}>
          <h3>About</h3>
        </a>
      </div>

      <div id={styles.content} className="content">
        <br/>
        <h2>Test Variable: {testVariable}</h2>

        <button id={styles.incrementButton} onClick={setTestVariable(1)}>Set Test Variable to 1</button>

      </div>

    </div>
  )
}

export default Home

When I tap the button the variable on my page changes to 1, however when I switch pages the variable goes back to 0. I also receive no errors of any sort. All feedback is greatly appreciated! Thanks for your time.

Chrome Extension: What is the alternative of jQuery for DOM operations in background.js?

This new version 3 is making my development process very difficult. I am fetching a page HTML in background.js and now I want to perform certain operations like fetching links based on className etc. I tried to load jQuery but it gives error:

bg-loader.js:4 TypeError: Cannot read properties of undefined (reading 'createElement')
    at ce (jquery.js:2:7312)
    at jquery.js:2:23143
    at jquery.js:2:23839
    at jquery.js:2:220
    at jquery.js:2:225
    at bg-loader.js:2:5

I use the following code in bg-loader.js:

importScripts('jquery.js', 'background.js' /*, and so on */);

Ajax is not redirecting towards the next page (dasboard) page after model form submission?

I am using ajax for opening up an OTP form, after successful form submission, the form disappears but the page does not change, It does not redirect to the page backend is redirecting to. Please help.

After submission of the form, I want it to redirect to dashboard as mentioned in backend code below

HTML

<div class="modal fade review_modal" id="review_modal" tabindex="-1" role="dialog"
aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
    <div class="modal-content">
        <a href="#" class="close_modal" data-dismiss="modal">&#10006;</a>
            <div class="text-box">
                <h1>Verify OTP</h1>
                <div class="form-group">
                    <input type="text" placeholder="Enter OTP" name="otp" id="otp" required>
                </div>
                <div class="form-group">
                    <input value="1" class="slider" name="istrusted" id="istrusted" type="checkbox" checked="true"/>
                    <input value="0" class="" name="istrusted" id="istrusted" type="checkbox"/>
                    <label for="istrusted"> Do you want to add this device as your trusted device</label><br><br>
                </div>
                <div class="form-group mt-4">
                    <button id="otp_proceed_button" class="btn btn-primary" type="submit">Proceed</button>
                </div>
            </div>
    </div>
</div>
</div>


Ajax

<script>
$(window).on('load', function() {
        $('#review_modal').modal('show');
    }    
);

$('button').click(function(e) {
    e.preventDefault();
    var otp = $('#otp').val();
    var istrusted = $('#istrusted').val();
    $.ajax({
        type: "POST",
        url: "/device_verify",
        data : {otp: otp, istrusted: istrusted},
        success: function(data){
            $('#review_modal').hide();
        }
    });
});

</script>


backend code for redirection

@accounts_blueprint.route('/device_verify', methods=['POST'])
@limiter.limit('10 per minute')
def verifydevice():
    mobileno = session.get('mobileno')
    existing_user = sessiondb.query(User).filter(User.mobileno == mobileno).first()
    otp=request.form.get('otp')
    istrusted= request.form.get('istrusted')
    deviceVerfied = verify_device(request, otp, istrusted, existing_user)
    if deviceVerfied  == True:
        login_user(existing_user)
        add_last_login()
        add_investor_status()
        session.pop('mobileno')
        return redirect(url_for('dashboard_blueprint.dashboard'))


Why my documentelement.onclick function is not working?

I wanted build a web 8ball app, I wanted to use PHP for it. I included jQuery and I set everything up, but my .onclick function wasnt working

<!doctype HTML>
<html>
  <head>
    <title>Test</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
  </head>
  <link rel="stylesheet" href="https://easycss.bookie0.repl.co/dark.css">
  <link rel="stylesheet" href="style.css">
  <body>
    <nav><h1>Hello</h1></nav>
    <div class="content">
      <p id="output">Ask me anything.</p>
      <form onsubmit="return false" id="formm">
      <input id="userinput" placeholder="Say something." type="text" required>
      <button type="submit" id="submitsend">Send</button>
      </form>
    </div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script defer>
      
      var button = document.getElementById("submitsend")
      
      button.onclick = async function() {
        alert("h")
        input.value = ""
        var input = document.getElementById("userinput")
      var output = document.getElementById("output")
      var result = await $.getJSON("https://api.eriner.repl.co/fun/8ball")
      output.innerHTML = result.answer
      }
    </script>
  </body>
</html>