/
packages.js
46 lines (42 loc) · 1.09 KB
/
packages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import withRender from './packages.html';
export const packages = [];
export const emitter = new (require('events').EventEmitter)();
export function addPackage(name, notify = true) {
packages.indexOf(name) === -1 && packages.push(name);
notify && emitter.emit('change');
}
export function removePackage(name, notify = true) {
packages.splice(packages.indexOf(name), 1);
notify && emitter.emit('change');
}
export function setPackages(val, notify = true) {
packages.splice(0, packages.length, ...val);
notify && emitter.emit('change');
}
export default withRender({
props: {
onSubmit: Function,
isUsingPresetComparisons: Boolean,
},
data() {
return {
isValid: false,
};
},
methods: {
handleClickSubmit(e) {
e && e.preventDefault() && e.stopPropagation();
this.submit();
},
submit(val) {
this.onSubmit(this.$refs.textbox.value.trim());
this.$refs.textbox.value = '';
},
handleEnter() {
this.isValid && this.submit();
},
validate() {
this.isValid = this.$refs.textbox.value.trim() !== '';
},
},
});