Skip to content

Commit 9f4e40a

Browse files
author
User
committed
added Global APIs
1 parent fbc2ee3 commit 9f4e40a

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

API.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const GlobalAPI = [
1717
G_API.EXTEND,
1818
G_API.NEXT_TICK,
1919
G_API.SET,
20-
G_API.DELETE
20+
G_API.DELETE,
21+
G_API.DIRECTIVE,
22+
G_API.FILTER
2123
]
2224

2325

apis/globalapi.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const chalk = require('chalk')
22
const custom = require('../customcolors')
33
const colorComment = custom.colorComment
4-
const colorPrimitive = custom.colorPrimitive
54
const colorError = custom.colorError
65
const colorArgs = custom.colorArgs
76

@@ -85,10 +84,43 @@ const DELETE = {
8584
}
8685

8786
const DIRECTIVE = {
88-
87+
category: 'Global API',
88+
name: 'Vue.directive(id,[definition])',
89+
arguments: [
90+
`{string} id`,
91+
`{Function | Object} [definition]`
92+
],
93+
usage: `Register or retrieve a global directive`,
94+
example: `${colorComment('// register')}
95+
Vue.directive(${chalk.green("'my-directive'")}, {
96+
bind: ${chalk.blue('function')} () {},
97+
inserted: ${chalk.blue('function')} () {},
98+
update: ${chalk.blue('function')} () {},
99+
componentUpdated: ${chalk.blue('function')} () {},
100+
unbind: ${chalk.blue('function')} () {},
101+
})
102+
${colorComment('// register (simple function directive')}
103+
Vue.directive(${chalk.green("'my-directive'")}, ${chalk.blue('function')} () {
104+
${colorComment('// this will be called as `bind` and `update`')}
105+
})
106+
${colorComment(` getter, return the directive definition if registered`)}
107+
${colorArgs('var')} myDirective = Vue.directive(${chalk.green("'my-directive'")})`
89108
}
90109

91110
const FILTER = {
111+
category: 'Global API',
112+
name: 'Vue.filter(id,[definition])',
113+
arguments:[
114+
`{string} id`,
115+
`{Function} [definition]`
116+
],
117+
usage: `Register or retrieve a global filter.`,
118+
example: `${colorComment('// register')}
119+
Vue.filter(${chalk.green("'my-filter'")}, ${chalk.blue('function')} (value){
120+
${colorComment('// return processed value')}
121+
})
122+
${colorComment('// getter, return the filter is registered')}
123+
${colorArgs('var')} myFilter = Vue.filter(${chalk.green("'my-filter'")})`
92124

93125
}
94126

@@ -116,5 +148,7 @@ module.exports = {
116148
EXTEND,
117149
NEXT_TICK,
118150
SET,
119-
DELETE
151+
DELETE,
152+
DIRECTIVE,
153+
FILTER
120154
}

logfunctions/logglobalapi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module.exports = {
77
`
88
${chalk.green('Category:')} ${obj.category}
99
${chalk.green('Name:')} ${obj.name + '\n'}
10-
* Arguments:
10+
* Arguments (${obj.arguments.length}):
1111
${obj.arguments.map((arg, index) => {
12-
return `${index+1} ${args(arg)} `
12+
return `${index+1}: ${args(arg)} `
1313
}).join(" ")}
1414
${obj.returns ? `* Returns: ${obj.returns}` : ''}
1515
* Usage: ${obj.usage}

vue-help.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,16 @@ V.command('delete', 'Outputs "Global API: #Vue.delete(target,key)"').action(func
8787
const dlt = ga[3]
8888
this.log(LGA.logGlobalAPI(dlt))
8989
callback()
90+
})
91+
92+
V.command('directive', 'Outputs "Global API: #Vue.directive(id,[definition])"').action(function(args, callback){
93+
const dir = ga[4]
94+
this.log(LGA.logGlobalAPI(dir))
95+
callback()
96+
})
97+
98+
V.command('filter', 'Outputs "Global API: #Vue.filter(id,[definition])"').action(function(args, callback){
99+
const flt = ga[5]
100+
this.log(LGA.logGlobalAPI(flt))
101+
callback()
90102
})

0 commit comments

Comments
 (0)