Skip to content

Commit 1f96468

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

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

apis/instancedata.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,66 @@ const VM_$WATCH = {
2929
because they reference the same Object/Array.
3030
Vue doesn’t keep a copy of the pre-mutate value.`,
3131
example: `
32-
// keypath
33-
vm.$watch('a.b.c', function (newVal, oldVal) {
34-
// do something
32+
${colorComment(`// keypath`)}
33+
vm.$watch(${chalk.green(`'a.b.c'`)}, ${chalk.blue(`function`)} (newVal, oldVal) {
34+
${colorComment(`// do something`)}
3535
})
36-
// function
36+
${colorComment(`// function`)}
3737
vm.$watch(
3838
function () {
3939
return this.a + this.b
4040
},
4141
function (newVal, oldVal) {
42-
// do something
42+
${colorComment(`// do something`)}
4343
}
4444
)
45+
${colorArgs(`vm.$watch`)} returns an unwatch function that stops firing the callback:
46+
${colorArgs(`var`)} unwatch = vm.$watch(${chalk.green(`'a'`)}, cb)
47+
${colorComment(`// later, teardown the watcher`)}
48+
unwatch()
49+
50+
* ${chalk.bold(`Option: deep`)}
51+
To also detect nested value changes inside Objects, you need to pass in ${colorArgs('deep: true')} in the
52+
options argument.
53+
Note that you don’t need to do so to listen for Array mutations.
54+
55+
vm.$watch(${chalk.green(`'someObject'`)}, callback, {
56+
deep: ${colorPrimitive(`true`)}
57+
})
58+
vm.someObject.nestedValue = ${colorPrimitive(`123`)}
59+
${colorComment(`// callback is fired`)}
60+
61+
* ${chalk.bold(`Option: immediate`)}
62+
Passing in ${colorArgs(`immediate: true`)} in the option will trigger the callback immediately
63+
with the current value of the expression:
64+
vm.$watch(${chalk.green(`'a'`)}, callback, {
65+
immediate: ${colorPrimitive(`true`)}
66+
})
67+
${colorComment(`// callback is fired immediately with current value of 'a'`)}
4568
`
4669
}
47-
const VM_$SET = {}
48-
const VM_$DELETE = {}
70+
const VM_$SET = {
71+
category: cat,
72+
name: 'vm.$set(target,key,value)',
73+
arguments: [
74+
`{Object | Array) target`,
75+
`{string | number} key`,
76+
`{any} value`
77+
],
78+
returns: `the set value.`,
79+
usage: `This is the ${chalk.bold(`alias`)} of the global ${colorArgs(`Vue.set`)}.`
80+
}
81+
82+
const VM_$DELETE = {
83+
category: cat,
84+
name: `vm.$delete(target,key)`,
85+
arguments:[
86+
`{Object | Array} target`,
87+
`{string | number} key`
88+
],
89+
usage: `This is the ${chalk.bold(`alias`)} of the global ${colorArgs(`Vue.delete`)}.`
90+
91+
}
4992

5093
module.exports = {
5194
VM_$WATCH,

vue-help.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,22 @@ V.command('vm.$listeners', 'Instance Properties: #vm.$listeners').action(functio
446446

447447
// Instance Methods/Data
448448

449-
V.command('vm.$watch', 'Instance Properties: #vm.$watch(expOrFn,callback,[options]').action(function(args, callback){
449+
V.command('vm.$watch', 'Instance Methods/Data: #vm.$watch(expOrFn,callback,[options])').action(function(args, callback){
450450
const w = id[0]
451451
this.log(LI.logInstance(w))
452452
callback()
453453
})
454+
455+
V.command('vm.$set', 'Instance Methods/Data: #vm.$set(target,key,value)').action(function(args, callback){
456+
const w = id[1]
457+
this.log(LI.logInstance(w))
458+
callback()
459+
})
460+
461+
V.command('vm.$delete', 'Instance Methods/Data: #vm.$delete(target,key)').action(function(args, callback){
462+
const w = id[2]
463+
this.log(LI.logInstance(w))
464+
callback()
465+
})
466+
467+
// Instance Methods/Events

0 commit comments

Comments
 (0)