Watcher of date type being triggered when dispatch/trigger
See original GitHub issueGiven a following component (Bar.vue):
<template>
<div>
<div class="date">{{dateValue2.toISOString()}}</div>
<div class="int">{{intValue2}}</div>
<button @click="change">Change</button>
</div>
</template>
<script>
export default {
props: ['dateValue', 'intValue'],
data(){
return {
dateValue2: this.dateValue,
intValue2: this.intValue
};
},
watch: {
dateValue(newVal, oldVal){
this.dateValue2 = this.dateValue;
},
intValue(newVal, oldVal){
this.intValue2 = this.intValue;
}
},
methods:{
change(){
this.dateValue2 = new Date(
this.dateValue2.getFullYear(),
this.dateValue2.getMonth(),
1
);
this.intValue2 += 1;
}
}
};
</script>
And this test
import { mount } from 'avoriaz'
import Bar from '../src/components/Bar.vue'
var test = require('tape')
test('set date', (t) => {
const wrapper = mount(Bar, {
propsData:{
dateValue: new Date(2017, 5, 21),
intValue: 1
}
});
let date = wrapper.find('.date')[0];
let int = wrapper.find('.int')[0];
t.is(date.text(), new Date(2017, 5, 21).toISOString(), 'dateValue2 before');
t.is(int.text(), '1', 'intValue2 before');
wrapper.find('button')[0].dispatch('click');
t.is(date.text(), new Date(2017, 5, 1).toISOString(), 'dateValue2 after');
t.is(int.text(), '2', 'intValue2 after');
t.end();
});
The test for dateValue2 after
would fail. I found that the dispatch('click')
has somehow triggered the watcher dateValue
thus re-assign the value.
This test would pass for version 1.14.0
, but fail at current 2.4.0
.
I have created the test here: https://github.com/jackysee/avoriaz-tape-example
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why does watcher trigger twice? - Stack Overflow
I think this has to do with a watcher inside the component. If you change the date by clicking it, it sets the...
Read more >Sensors and Triggers — StackStorm 3.8.0 documentation
Triggers are StackStorm constructs that identify the incoming events to StackStorm. A trigger is a tuple of type (string) and optional parameters (object)....
Read more >Watch triggered even if value is not changed #2231 - GitHub
watch requires watching a specific data source and applies side effects in a separate callback function. It also is lazy by default -...
Read more >Watcher schedule trigger | Elasticsearch Guide [8.5] | Elastic
Watcher schedule triggeredit. Schedule triggers define when the watch execution should start based on date and time. All times are specified in UTC...
Read more >How do I use the date-based trigger and actions in an ...
Watch a video. To see how you can use date-based triggers and actions in automation, watch the video below.
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 Free
Top 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
This should be fixed in 2.4.1
Only watchers that match the value changed will run
Yeah,
update
runs all the watchers, andtrigger
runs update. The reason I ran the watchers was to fix with this issue - #64.Temporary solution is to use 1.14.0 until I come up with a solution