question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: determine if a reactive object is observed by any Vue instance

See original GitHub issue

I would like to request a new feature. I want to determine if a reactive object is observed by any Vue instances.

Example:

var obj1 = {name: 'obj1'};
var obj2 = {name: 'obj2'};

var app = new Vue({
  el: '#app',
  data: {
    item: {}
  },
  mounted: function onMounted(){
    this.item = obj1;
    this.item = obj2;
  },
  methods: {
    pickItem: function pickItem() {
    	this.item = items[this.pickedElemId];
    }
  }
});

I want to determine if obj1 is observed by any Vue instances. In this example it is clear that the obj2 is observed but obj1 is not.

The reasons behind this feature request is discussed in this issue: https://github.com/vuejs/vue/issues/4384

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
fnlctrlcommented, Dec 10, 2016

You can already check it now using the (private) __ob__ property.

if (obj.__ob__) { /*It's observed by vue*/ }

Though I don’t know if it’s worth adding a public API for it. Maybe __ob__ is good enough (at least for 2.x)?

0reactions
kailniriscommented, Dec 15, 2016

The pattern discussed in this (https://github.com/vuejs/vue/issues/4384) issue is a suitable workaround for the problem so this feature request is unnecessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reactivity Fundamentals - Vue.js
It only works for object types (objects, arrays, and collection types such as Map and Set ). It cannot hold primitive types such...
Read more >
Your guide to reactivity in Vue.js - LogRocket Blog
Get a better understanding of reactivity in Vue.js and see how to achieve reactivity in Vue 3 using proxies.
Read more >
Reactivity In Vue - Smashing Magazine
Here, we imported the reactive method from Vue, and then we declared our user variable by passing its value to this function as...
Read more >
Thought on Vue 3 Composition API - `reactive()` considered ...
reactive (obj) will return a new object that looks exactly the same as obj , but any mutation to the new object will...
Read more >
Understanding the New Reactivity System in Vue 3 - SitePoint
For each component instance, Vue creates a dependencies watcher instance. Any properties collected/tracked as dependencies during the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found