-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Json-editor multiple instance #894
Conversation
height: { type: Number, default: 250 } | ||
}, | ||
data() { | ||
return { | ||
editor: null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of putting the editor
variable in the component state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is necessary to have the editor
variable scoped to the component to be able to use several instances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we let the editor
in global:
Hypothesis: if we add multiple json-editors there will still be only one editor
variable wich will be overrided each time we instanciate a new json-editor.
Actual consequence: Call the setContent method of a json-editor component will always set the content on the last instanciated editor no matter wich json-editor's method we call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. The editor
variable is scoped to the JSONEditor.vue module, which is a singleton, in the CommonJS modules model. The module exports a VueJS Component config, which is passed to the Vue
constructor each time this component is instantiated. But this config has a reference to the editor
variable, which is actually overwritten, as you rightly say, each time the component is instantiated. By putting the variable inside the data
structure, you make it local to the component instead, which is obviously not a singleton. This is a nice thing to keep in mind for future developments.
I still don't like the idea of putting a complex object (i.e. one that has attributes and functions) inside the data
structure, because it is meant to keep track of the state of the component, yet this object is just logic to make the editor work. We should find a way to replicate this reference each time the component is created, and avoid the reference to be overwritten.
I am not really hurried to ship this fix, but if you are, we can keep this enhancement for later. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merge this PR I'll create an issue concerning the refacto of the json-editor and we'll probably need a workshop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we had the same code-formatting rules.
phone: 'Blackberry', | ||
car: 'Laguna' | ||
}, | ||
skill: { | ||
name: 'managment', | ||
level: '1' | ||
}, | ||
job: 'Always asking Esteban to do his job', | ||
employeeOfTheMonthSince: '1996-07-10' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
What does this PR do ?
Fix #893 Json-editor multiple instance
How should this be manually tested?