-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstanceevents.js
68 lines (65 loc) · 2.2 KB
/
instanceevents.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const chalk = require('chalk')
const custom = require('../customcolors')
const colorComment = custom.colorComment
const colorPrimitive = custom.colorPrimitive
const colorError = custom.colorError
const colorArgs = custom.colorArgs
const cat = 'Instance Methods/Events'
const VM_$ON = {
category: cat,
name: `vm.$on(event, callback)`,
arguments:[
`{string | Array<string>} event`,
`{Function} callback`
],
usage: `Listen for a custom event on the current vm.
Events can be triggered by ${colorArgs(`vm.$emit`)}. The callback will receive
all the additional arguments passed into these event-triggering methods.`,
example: `
vm.$on(${chalk.green(`'test'`)}, ${chalk.blue(`function`)} (msg) {
${chalk.green(`console`)}.log(msg)
})
vm.$emit(${chalk.green(`'test'`)}, ${chalk.green(`'hi'`)})
${colorComment(`// -> "hi"`)}
`
}
const VM_$ONCE = {
category: cat,
name: `vm.$once(event,callback)`,
arguments:[
`{string} event`,
`{Function} callback`
],
usage: `Listen for a custom event, but only once.
The listener will be removed once it triggers for the first time.`
}
const VM_$OFF = {
category: cat,
name: `vm.$off([event,callback])`,
arguments: [
`{string} [event]`,
`{Function} [callback]`
],
usage: `Remove custom event listener(s).
* If no arguments are provided, remove all event listeners;
* If only the event is provided, remove all listeners for that event;
* If both event and callback are given, remove the listener
for that specific callback only.
`
}
const VM_$EMIT = {
category: cat,
name: `vm.$emit(event,[...args])`,
arguments: [
`{string} event`,
`[...args]`
],
usage: `Trigger an event on the current instance. Any additional
arguments will be passed into the listener’s callback function.`
}
module.exports = {
VM_$ON,
VM_$ONCE,
VM_$OFF,
VM_$EMIT
}