@@ -29,32 +29,24 @@ const masterKeyWarn = () => {
2929*/
3030
3131AV . init = ( ...args ) => {
32- switch ( args . length ) {
33- case 1 :
34- const options = args [ 0 ] ;
35- if ( typeof options === 'object' ) {
36- if ( process . env . CLIENT_PLATFORM && options . masterKey ) {
37- masterKeyWarn ( ) ;
38- }
39- initialize ( options . appId , options . appKey , options . masterKey , options . hookKey ) ;
40- request . setServerUrlByRegion ( options . region ) ;
41- AV . _config . disableCurrentUser = options . disableCurrentUser ;
42- } else {
43- throw new Error ( 'AV.init(): Parameter is not correct.' ) ;
44- }
45- break ;
46- // 兼容旧版本的初始化方法
47- case 2 :
48- case 3 :
49- console . warn ( 'Please use AV.init() to replace AV.initialize(), ' +
50- 'AV.init() need an Object param, like { appId: \'YOUR_APP_ID\', appKey: \'YOUR_APP_KEY\' } . ' +
51- 'Docs: https://leancloud.cn/docs/sdk_setup-js.html' ) ;
52- if ( process . env . CLIENT_PLATFORM && args . length === 3 ) {
32+ if ( args . length === 1 ) {
33+ const options = args [ 0 ] ;
34+ if ( typeof options === 'object' ) {
35+ if ( process . env . CLIENT_PLATFORM && options . masterKey ) {
5336 masterKeyWarn ( ) ;
5437 }
55- initialize ( ...args ) ;
56- request . setServerUrlByRegion ( 'cn' ) ;
57- break ;
38+ initialize ( options . appId , options . appKey , options . masterKey , options . hookKey ) ;
39+ request . setServerUrlByRegion ( options . region ) ;
40+ } else {
41+ throw new Error ( 'AV.init(): Parameter is not correct.' ) ;
42+ }
43+ } else {
44+ // 兼容旧版本的初始化方法
45+ if ( process . env . CLIENT_PLATFORM && args [ 3 ] ) {
46+ masterKeyWarn ( ) ;
47+ }
48+ initialize ( ...args ) ;
49+ request . setServerUrlByRegion ( 'cn' ) ;
5850 }
5951} ;
6052
0 commit comments