Skip to content

Commit 80b2938

Browse files
committed
feat: support for @change and @init events (vue)
1 parent 5593c99 commit 80b2938

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/ui-predicate-vue/examples/simple.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div id="app">
33
<h1>Simple ui-predicate usage</h1>
4-
<ui-predicate :config="config" @onChange="onChange"></ui-predicate>
4+
<ui-predicate :config="config" @change="onChange" @init="onChange"></ui-predicate>
55
<p>Tips: Use "alt + click" to create a sub-group.</p>
66
<pre>{{ ast }}</pre>
77
</div>

packages/ui-predicate-vue/src/ui-predicate.vue

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ module.exports = {
7474
this.setIsInAddCompoundMode(false);
7575
}
7676
},
77+
onChange(ctrl) {
78+
// emit 'change' event
79+
this.$emit('change', ctrl);
80+
},
7781
},
7882
mounted() {
7983
const vm = this;
@@ -86,6 +90,9 @@ module.exports = {
8690
vm.ctrl = ctrl;
8791
vm.root = ctrl.root;
8892
vm.columns = ctrl.columns;
93+
// emit 'init' event
94+
vm.$emit('init', ctrl);
95+
ctrl.on('changed', vm.onChange);
8996
},
9097
err => {
9198
console.error(err);
@@ -97,6 +104,7 @@ module.exports = {
97104
window.addEventListener('keydown', this.onAltPressed);
98105
},
99106
destroyed() {
107+
this.ctrl.off();
100108
window.removeEventListener('keyup', this.onAltReleased);
101109
window.removeEventListener('keydown', this.onAltPressed);
102110
},

0 commit comments

Comments
 (0)