Make it possible to teardown a $watch when immediate is set
See original GitHub issueWhat problem does this feature solve?
I use the following pattern to wait for a condition to hold:
const unwatch = this.$watch(function () {
return this.queue.find((element) => element.shown === false);
}, function (newValue, oldValue) {
if (!newValue) return;
unwatch();
// There is an element in the queue with shown === false.
});
The problem is that this pattern is not possible to use if I also want callback to be called if the condition holds already when $watch
is called. This is done by setting immediate
to true
. But then unwatch
is not yet set because $watch
has not returned.
I could be checking if the condition holds before creating $watch
but this makes the code more complicated and in parts duplicated.
What does the proposed API look like?
In Meteor’s Tracker this is solved by providing access to current computation as an argument to the callback function. Maybe Vue could do the same and provide unwatch
as the third argument to the callback (newValue, oldValue, unwatch)
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
HOW TO RELEASE A LOADED MAINSPRING INSIDE YOUR ...
Please do not forget to subscribe and hit that bell for future notification! ... to produce more educational videos for everyone to watch...
Read more >Trying to FIX: Faulty 1980s Digital Watch from eBay - YouTube
Hi, in the video I attempt to repair an old quartz digital watch from the 1980s. I purchased it faulty from eBay and...
Read more >How to Replace a Watch Movement - Watch Repair Guides
A screw off watch back will have large notches around the edges of the back of the watch. Use a Case Opener wrench...
Read more >Apple Watch Teardown - iFixit
1. Ladies and gentlemen, the Apple Watch has arrived. But before we get down to the brass tacks, here's a quick overview of...
Read more >Apple Watch Series 4 Teardown - iFixit
1. Apple Watch patient profile: 2. While these black squares may look outwardly similar, X-rays from our experts at Creative Electron reveal radically...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have to say that I was hit with the same issue. Now my code looks like:
And it’s not really self-explaining on why I must execute the condition manually first. Extending the API of the watch function should not break it, as mentionned.
The implementation is also very easy. Currently there is:
And in my proposal would be:
Where is this breaking any API anywhere?