@@ -5,10 +5,60 @@ const colorPrimitive = custom.colorPrimitive
5
5
const colorError = custom . colorError
6
6
const colorArgs = custom . colorArgs
7
7
8
- const VM_$ON = { }
9
- const VM_$ONCE = { }
10
- const VM_$OFF = { }
11
- const VM_$EMIT = { }
8
+ const cat = 'Instance Methods/Events'
9
+
10
+ const VM_$ON = {
11
+ category : cat ,
12
+ name : `vm.$on(event, callback)` ,
13
+ arguments :[
14
+ `{string | Array<string>} event` ,
15
+ `{Function} callback`
16
+ ] ,
17
+ usage : `Listen for a custom event on the current vm.
18
+ Events can be triggered by ${ colorArgs ( `vm.$emit` ) } . The callback will receive
19
+ all the additional arguments passed into these event-triggering methods.` ,
20
+ example : `
21
+ vm.$on(${ chalk . green ( `'test'` ) } , ${ chalk . blue ( `function` ) } (msg) {
22
+ ${ chalk . green ( `console` ) } .log(msg)
23
+ })
24
+ vm.$emit(${ chalk . green ( `'test'` ) } , ${ chalk . green ( `'hi'` ) } )
25
+ ${ colorComment ( `// -> "hi"` ) }
26
+ `
27
+ }
28
+ const VM_$ONCE = {
29
+ category : cat ,
30
+ name : `vm.$once(event,callback)` ,
31
+ arguments :[
32
+ `{string} event` ,
33
+ `{Function} callback`
34
+ ] ,
35
+ usage : `Listen for a custom event, but only once.
36
+ The listener will be removed once it triggers for the first time.`
37
+ }
38
+ const VM_$OFF = {
39
+ category : cat ,
40
+ name : `vm.$off([event,callback])` ,
41
+ arguments : [
42
+ `{string} [event]` ,
43
+ `{Function} [callback]`
44
+ ] ,
45
+ usage : `Remove custom event listener(s).
46
+ * If no arguments are provided, remove all event listeners;
47
+ * If only the event is provided, remove all listeners for that event;
48
+ * If both event and callback are given, remove the listener
49
+ for that specific callback only.
50
+ `
51
+ }
52
+ const VM_$EMIT = {
53
+ category : cat ,
54
+ name : `vm.$emit(event,[...args])` ,
55
+ arguments : [
56
+ `{string} event` ,
57
+ `[...args]`
58
+ ] ,
59
+ usage : `Trigger an event on the current instance. Any additional
60
+ arguments will be passed into the listener’s callback function.`
61
+ }
12
62
13
63
module . exports = {
14
64
VM_$ON,
0 commit comments