vue-observable | IntersectionObserver , MutationObserver | Frontend Plugin library
kandi X-RAY | vue-observable Summary
kandi X-RAY | vue-observable Summary
IntersectionObserver, MutationObserver and PerformanceObserver in Vue.js
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of vue-observable
vue-observable Key Features
vue-observable Examples and Code Snippets
Community Discussions
Trending Discussions on vue-observable
QUESTION
Do we need to destroy, or disconnect the observable created when using Vue.observable()
?
https://vuejs.org/v2/api/#Vue-observable
Usually it's a good practice to destroy any new object and to clear timeouts and whatever can cause memory leaks on beforeDestroy
.
But I am wondering if the internal Vue Observer
instances are also destroyed by an internal mechanism on component destroy (like the component itself), and if not how to properly stop observing and get rid of this data?
Even after looking into the source code of Vue, it is still unclear wether I should destroy an Observer. The Observer
class (created internally with Vue.observable()
) does not seem to have any method to stop observing and it's not documented in official Vue docs.
Please provide a reference to your answer so I can know more about it.
...ANSWER
Answered 2020-Sep-18 at 07:04Cleanup is needed when working with some browser API's, which create resources outside of JavaScript runtime (as setInterval
) or when using non-Vue libraries which create new DOM nodes.
Vue.observable
just modify object passed using Object.defineProperty() - result of the call is same JS object. And because JS is garbage collected language/runtime, no manual cleanup/destroy is needed. Objects are garbage collected automatically by runtime (no Vue) when there is no reference to it.
Vue 3 reactive()
is different because result of the call is new object - proxy - but it is still normal JS object so it is garbage collected automatically...
QUESTION
I'm using Vuex, as state handler AND as tools to share data between my components which are not necessarily "father-son".
Using Vuex, i want to share a complex object get from an external library. This object has methods to change its attributes.
For this object I do not care to centralize its status, but want a way to share it between components.
I thought (and discarded) different solutions: - disable strict mode. But I want to have it for all other cases, is very useful! - Do not use Vuex. But it is very convenient and in addition it is well integrated with debugging tools (chrome plugin for example) - replace Vuex with a more simple store: https://austincooper.dev/2019/08/09/vue-observable-state-store. Same problems as before
So, what is the best way to share complex data from other libraries? I would like to use vuex, but I can't find the cleanest solution!
An example of my problem: (Press get more items and a console error will appear) https://codepen.io/ale-grosselle/pen/dyyxyMr
...ANSWER
Answered 2019-Nov-28 at 10:12Even though I understand your reason to use Vuex to try to share a object through your application, I think that it isn't exactly the purpose, since the objective is to share a Single Source of Data through your application, and you're exactly saying that you don't want (exactly) that.
You could, if you want, share a singleton instance of Collection class, exported by a module, and access it through your application using the Provide/Inject API.
Other problem that you'll have (since I've tried doing almost the same in a project) is that the state of the store has to be serializable, and if you don't make any special treatment, the methods of your Collection will be lost when you use the "time travel" from Chrome DevTools (since the state is serialized and deserialized using JSON.stringify/JSON.parse).
I know that isn't exactly what you wanted, but Vuex doesn't seem to be what your looking to use in your situation.
Edit: I've updated your example by using the idea that I gave above, and used Vue.observable to make the object reactive to Vue, you may check it here:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vue-observable
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page