Skip to content

Commit 17064c9

Browse files
author
User
committed
added Instance Methods/Data APIs
1 parent 9d7afda commit 17064c9

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

API.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const O_A = require('./apis/optionsassets')
77
const O_C = require('./apis/optionscomposition')
88
const O_M = require('./apis/optionsmisc')
99
const I_P = require('./apis/instanceproperties')
10+
const I_D = require('./apis/instancedata')
11+
1012

1113
const GlobalConfig = [
1214
G_C.SILENT,
@@ -103,6 +105,12 @@ const InstanceProperties = [
103105
I_P.VM_$LISTENERS
104106
]
105107

108+
const InstanceData = [
109+
I_D.VM_$WATCH,
110+
I_D.VM_$SET,
111+
I_D.VM_$DELETE
112+
]
113+
106114

107115
module.exports = {
108116
GlobalConfig,
@@ -113,5 +121,6 @@ module.exports = {
113121
OptionsAssets,
114122
OptionsComposition,
115123
OptionsMisc,
116-
InstanceProperties
124+
InstanceProperties,
125+
InstanceData
117126
}

apis/instancedata.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const colorComment = custom.colorComment
4+
const colorPrimitive = custom.colorPrimitive
5+
const colorError = custom.colorError
6+
const colorArgs = custom.colorArgs
7+
8+
const cat = `Instance Methods/Data`
9+
const VM_$WATCH = {
10+
category: cat,
11+
name: `vm.$watch(expOrFn,callback,[options])`,
12+
arguments:[
13+
`{string | Function} expOrFn`,
14+
`{Function | Object} callback`,
15+
`{Object} [options]
16+
{ {Object} [options]:
17+
* {boolean} deep\n
18+
* {boolean} immediate
19+
}`
20+
],
21+
returns: `{Function} unwatch`,
22+
usage: `Watch an expression or a computed function on the Vue instance
23+
for changes. The callback gets called with the new value
24+
and the old value. The expression only accepts simple dot-delimited paths.
25+
For more complex expression, use a function instead.
26+
27+
Note: when mutating (rather than replacing) an Object
28+
or an Array, the old value will be the same as new value
29+
because they reference the same Object/Array.
30+
Vue doesn’t keep a copy of the pre-mutate value.`,
31+
example: `
32+
// keypath
33+
vm.$watch('a.b.c', function (newVal, oldVal) {
34+
// do something
35+
})
36+
// function
37+
vm.$watch(
38+
function () {
39+
return this.a + this.b
40+
},
41+
function (newVal, oldVal) {
42+
// do something
43+
}
44+
)
45+
`
46+
}
47+
const VM_$SET = {}
48+
const VM_$DELETE = {}
49+
50+
module.exports = {
51+
VM_$WATCH,
52+
VM_$SET,
53+
VM_$DELETE
54+
}

logfunctions/loginstance.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const chalk = require('chalk')
2+
const custom = require('../customcolors')
3+
const args = custom.colorArgs
4+
module.exports = {
5+
logInstance: function(obj){
6+
return(
7+
`
8+
${chalk.green('Category:')} ${obj.category}
9+
${chalk.green('Name:')} ${obj.name + '\n'}
10+
* Arguments (${obj.arguments.length}):
11+
${obj.arguments.map((arg, index) => {
12+
return `${index+1}: ${args(arg)} `
13+
}).join(" ")}
14+
${obj.returns ? `* Returns: ${args(obj.returns)}` : ''}
15+
* Usage: ${obj.usage}
16+
${obj.example ? `* Example: ${obj.example}` : ''}
17+
`
18+
)
19+
}
20+
}

logfunctions/logoptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ module.exports = {
1414
* Details: ${obj.details}
1515
${obj.example ? `* Example: ${obj.example}` : ''}
1616
`
17-
)
17+
)
1818
}
1919
}

vue-help.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const V = require('vorpal')()
22
const LGC = require('./logfunctions/logglobalconfig')
33
const LGA = require('./logfunctions/logglobalapi')
4+
const LI = require('./logfunctions/loginstance')
45
const O = require('./logfunctions/logoptions')
56
const api = require('./API')
67
const gc = api.GlobalConfig
@@ -12,6 +13,8 @@ const oa = api.OptionsAssets
1213
const oc = api.OptionsComposition
1314
const om = api.OptionsMisc
1415
const ip = api.InstanceProperties
16+
const id = api.InstanceData
17+
1518

1619
V.delimiter('vue-help$').show()
1720

@@ -439,4 +442,12 @@ V.command('vm.$listeners', 'Instance Properties: #vm.$listeners').action(functio
439442
const w = ip[12]
440443
this.log(O.logOptions(w))
441444
callback()
442-
})
445+
})
446+
447+
// Instance Methods/Data
448+
449+
V.command('vm.$watch', 'Instance Properties: #vm.$watch(expOrFn,callback,[options]').action(function(args, callback){
450+
const w = id[0]
451+
this.log(LI.logInstance(w))
452+
callback()
453+
})

0 commit comments

Comments
 (0)