Skip to content

Commit bdef300

Browse files
author
User
committed
new API
1 parent 4e806bc commit bdef300

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

API.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const G_C = require('./globalconfig/globalconfig')
33
const GlobalConfig = [
44
G_C.SILENT,
55
G_C.OPTION_MERGE_STRATEGIES,
6-
G_C.DEVTOOLS
6+
G_C.DEVTOOLS,
7+
G_C.ERROR_HANDLER,
8+
G_C.WARN_HANDLER
79
]
810

911

globalconfig/globalconfig.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const chalk = require('chalk')
22
const SILENT = {
33
category: 'Global Config',
4-
name: '#silent',
4+
name: 'silent',
55
type: 'boolean',
66
default: 'false',
77
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
88
details: 'Suppress all Vue logs and warnings',
99
}
1010
const OPTION_MERGE_STRATEGIES = {
1111
category: 'Global Config',
12-
name: '#optionMergeStrategies',
12+
name: 'optionMergeStrategies',
1313
type: '{ [key: string]: Function }',
1414
default: '{}',
1515
usage: `Vue.config.optionMergeStrategies._my_option = ${chalk.magentaBright('function')} (parent, child, vm) {
@@ -26,7 +26,7 @@ const OPTION_MERGE_STRATEGIES = {
2626
}
2727
const DEVTOOLS = {
2828
category: 'Global Config',
29-
name: '#devtools',
29+
name: 'devtools',
3030
type: 'boolean',
3131
default: `true ${chalk.white('(')} false ${chalk.white('in production builds)')}`,
3232
usage: `// make sure to set this synchronously immediately after loading Vue
@@ -35,19 +35,33 @@ const DEVTOOLS = {
3535
This option's default value is ${chalk.magentaBright('true')} in development builds and ${chalk.magentaBright('false')} in production builds.
3636
You can set it to ${chalk.magentaBright('true')} to enable inspection for production builds`
3737
}
38-
/*const SILENT = {
38+
const ERROR_HANDLER = {
3939
category: 'Global Config',
40-
name: '#silent',
41-
type: 'boolean',
42-
default: 'false',
43-
arguments: '',
44-
readOption: '',
45-
usage: `Vue.config.silent = ${chalk.magentaBright('true')}`,
46-
details: 'Suppress all Vue logs and warnings',
47-
example: ''
40+
name: 'errorHandler',
41+
type: 'Function',
42+
default: 'undefined',
43+
usage: `Vue.config.errorHandler = ${chalk.magentaBright('function')} (err, vm, info) {
44+
// handle error
45+
// 'info' is a Vue-specific error info, e.g. which lifecycle hook
46+
// the error was found in. Only available in 2.2.0+
47+
}`,
48+
details: `Assign a handler for uncaught errors during component render function
49+
and watchers. The handler gets called with the error and the Vue instance.`
4850
}
4951

50-
const SILENT = {
52+
const WARN_HANDLER = {
53+
category: 'Global Config',
54+
name: 'warnHandler',
55+
type: 'Function',
56+
default: 'undefined',
57+
usage: `Vue.config.warnHandler = ${chalk.magentaBright('function')} (msg, vm, trace) {
58+
// trace is the component hierarchy trace
59+
}`,
60+
details: `Assign a custom handler for runtime Vue warnings. Note this only works
61+
during development and is ignored in production.`
62+
}
63+
64+
/*const SILENT = {
5165
category: 'Global Config',
5266
name: '#silent',
5367
type: 'boolean',
@@ -122,5 +136,7 @@ const SILENT = {
122136
module.exports = {
123137
SILENT,
124138
OPTION_MERGE_STRATEGIES,
125-
DEVTOOLS
139+
DEVTOOLS,
140+
ERROR_HANDLER,
141+
WARN_HANDLER
126142
}

vue-help.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const gc = api.GlobalConfig
66

77
V.delimiter('vue-help$').show()
88

9+
// Global Config API
910

1011
V.command('silent', 'Outputs').action(function(args, callback){
1112
const silent= gc[0]
@@ -23,4 +24,16 @@ V.command('devtools', 'Outputs').action(function(args, callback){
2324
const devtools = gc[2]
2425
this.log(LGC.logGlobalConfig(devtools))
2526
callback()
27+
})
28+
29+
V.command('errorHandler', 'Outputs').action(function(args, callback){
30+
const errorHandler = gc[3]
31+
this.log(LGC.logGlobalConfig(errorHandler))
32+
callback()
33+
})
34+
35+
V.command('warnHandler', 'Outputs').action(function(args, callback){
36+
const warnHandler = gc[4]
37+
this.log(LGC.logGlobalConfig(warnHandler))
38+
callback()
2639
})

0 commit comments

Comments
 (0)