Is there a way to stop Vuex from causing issues with my class instance?

I am attempting to save a representation of a class in Vuex, specifically the EditorState from ProseMirror. The class's properties are mostly unchangeable externally, meaning that any modifications require replacing the existing instance with a new one in Vuex.

Due to this setup, Vue's change tracking is unnecessary and may even disrupt ProseMirror's internal processes. I am exploring ways to shield my object from Vue's influence and ensure it is treated as an isolated entity.

Answer №1

By following the advice of the highest-rated answer on this thread, I successfully resolved the issue by freezing my class instance before passing it to Vuex.

const store = new Store<AppState>({
    state: {
        editor: Object.freeze(editorState), // Using freeze due to Vue reactivity disturbances
        filename: null,
        metadata: {}
    },
    mutations: {
        updateDocument(context, transaction: Transaction) {
            console.log("updateDocument called");

            // Re-freeze to prevent modifications
            context.editor = Object.freeze(context.editor.apply(transaction));
        }
    },
    strict: process.env.NODE_ENV === "development"
});

While Object.freeze may not be recursive and doesn't impact ProseMirror's internal functionality, it does deter Vue from attempting to alter the object.

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

We could not locate the '/__webpack_hmr' directory as it is returning a

Our asp.net core web application utilizes Typescript. Everything was functioning properly until recently when I noticed a repetitive attempt to access http://localhost:50000/dist/__webpack_hmr, resulting in a 404 not found error. This is the content of my ...

Unavailability of dates in Json ajax DatePicker

After retrieving database records of dates and converting them into a JSON Object, I am attempting to pass the JSON to javascript. The goal is to make the DatePicker UI dynamic by marking the dates in the JSON as unavailable on the calendar. Unfortunately ...

How can AngularJS handle multiple routes using unique templates while sharing the same controller?

I am currently researching whether I can achieve the functionality described in the title. Here are my initial thoughts: Let's consider the following routes I have set up: .when('/', { templateUrl : 'partials/homepage.html&ap ...

Encountering issues with npm installation as npm ERR! code EACCES is appearing during the process

After attempting to install TypeScript using npm install -g typescript, an error message appears indicating a permission denied issue: npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/typescript npm ERR! errno -13 npm E ...

How to efficiently import Xlsx and csv files using AngularJS

I am looking for a way to extract data in json format from each line of xlsx and csv files using AngularJS. Currently, I am utilizing the angular-file-upload library to access the file as shown below: $scope.LatLongUploader = new FileUploader({ //url ...

What is the best way to obtain the current date in JavaScript in the format Mon-DD-YYYY?

Need help with getting the current date in Mon-DD-YYY format using JavaScript. I want to input today's date without the time into a date picker field. My current code is giving errors, below is what I have: Page.prototype.clickOnsessionDate = async f ...

Retrieve the most recent information from the API using axios and React hooks

I have access to an API that provides data, but I am only interested in the most recent information. The newest data is always located at the end of the dataset. For instance, if there are 50 points of data, the latest would be number 50. Can someone adv ...

Looking to fill every space? Try using React with MUI Grid!

I am currently using Material UI Grid to create an image grid, and I am facing challenges in eliminating the gaps between certain grid items. Despite attempting to modify the alignitems and justify values of the container, I have not been successful in r ...

Trouble with VueJS: @change event not triggered when <input> value changes

In my VueJS project, I am working with two separate components: One is a modal and the other is a form. Within the modal component, the user inputs a PIN which is then confirmed. This value is then set to an input tag in the form component to save it. T ...

Managing a high volume of HTTP requests within a React-Redux application

Seeking assistance with my react-redux app project. I have a substantial amount of data that has been divided into smaller files, allowing the user to choose a start and end time range. Upon clicking the "Fetch data" button, I create HTTP request promise ...

Solving the Dilemma of Ordering Table Rows by Value in JavaScript

I am currently working on a table and my goal is to display rows in an orderly manner based on the sum of their columns. Essentially, I want the rows with the highest values to be displayed first, followed by rows with second highest values, and so on. Des ...

Tips for creating a unique parent tag and child tag with onclick functionality on a b-form-checkbox without repeating code

As I work on a li tag with various child elements, including a b-form-checkbox, I encountered an issue. I want the checkbox to function properly when clicked anywhere inside the li tag, including on the checkbox itself. However, when I click directly on th ...

Is it possible to expand the CORS permissions to the routers directly from the app?

I have a couple of questions: Is it possible to just use cors() once in my server.js instead of having to call and use it in every router file? Can I simply require express once in my server.js without having to call it in all my router files? Currently, ...

Exploring the functionalities of class methods within an Angular export function

Is it possible to utilize a method from an exported function defined in a class file? export function MSALInstanceFactory(): IPublicClientApplication { return new PublicClientApplication({ auth: AzureService.getConfiguration(), <-------- Com ...

Navigating the complexities of extracting and storing a data type from a collection of objects

Dealing with a messy API that returns inconsistent values is quite challenging. Instead of manually creating types for each entry, I am looking for a way to infer the types programmatically. One approach could be by analyzing an array like this: const arr ...

JavaScript: What is the best way to increase the size of an array by adding new elements

I am attempting to generate an array containing the first 100 prime numbers. Here is the code I have written: var primeArray= []; var num= primeArray.length; function checkIfPrime(n) { if(n < 2) { return false; } for(i=2; i< ...

Error: The function nodemailer.createTransport is not defined or does not exist

I'm currently working on integrating nodemailer into my nodejs application for sending emails. Check out the code below: var express = require('express'); var nodemailer = require('node-mailer'); var app = express(); app.post(&a ...

Delayed data binding in Angular 7 is causing issues

My current struggle involves Angular's data binding delay. After altering the value of this.notAvailable, the frontend doesn't update the [class.hide] until about 5 seconds after execution. Oddly enough, the console.log outputs appear promptly ...

Schema for JSON object with dynamically generated keys

I have a specific request that follows a certain format: { "uuid_1": [{obj}, {obj}, {obj}], "uuid_2": [{obj}, {obj}], ... "uuid_n": [{obj}, {obj}], } The object 'obj' is a simple object that contains a f ...

What is the correct way to assign the products variable to the array retrieved from the API response?

I am currently trying to implement a primeblocks component and I am struggling with v-binding the dataTable to the response I receive from my API. My issue lies in the fact that when I console.log(productData), I am getting an array that contains another ...