-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
ANS=WX | ||
LIB=WeChat | ||
LibVERSION=5.0.3 | ||
LibVERSION=5.0.4 |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,104 @@ | ||
import { setNetwork, isGetNetWork } from '../../store/network' | ||
import { getServerTime, isGetServerTime } from '../../store/time' | ||
import { core, resetCore, setCoreParams } from '../../store/core' | ||
import { config } from '../../store/config' | ||
import { config, isInitConfig } from '../../store/config' | ||
import lifecycleHook from '../../store/lifecycleHook' | ||
import { getNow } from '../../store/time' | ||
|
||
/** | ||
* 准备就绪后开始上报数据 | ||
*/ | ||
|
||
interface callbackArrType { | ||
fn: (args: any[]) => void; | ||
arg: any; | ||
xwhen?: number; | ||
} | ||
|
||
const callbackArr: callbackArrType[] = [] | ||
let callbackArr: callbackArrType[] = [] | ||
let callbackfirstArr: callbackArrType[] = [] | ||
|
||
let isReady = false | ||
|
||
function ready (callback) { | ||
return function(...args: any[]) { | ||
|
||
// 没有获取过NetWork和ServerTime之前先把触发事件存起来,等NetWork和ServerTime获取过后再调用 | ||
if (!isGetNetWork || !isGetServerTime) { | ||
callbackArr.push({ | ||
fn: callback, | ||
arg: args | ||
// sdk是否准备就绪 | ||
export const isReady = () => isGetServerTime && isInitConfig && isGetNetWork | ||
|
||
// 执行缓存函数 | ||
export function implementAallbackArr () { | ||
|
||
|
||
if (isReady()) { | ||
|
||
// onReady函数,sdk生命周期钩子,sdk初次初始化完成(采集数据之前的准备工作已到位) | ||
lifecycleHook.onReady(config) | ||
|
||
// 执行sdk没有初始化完成之前缓存函数 | ||
if (callbackfirstArr && callbackArr.length) { | ||
callbackfirstArr.forEach(o => { | ||
return o.fn.apply(o.fn, o.arg) | ||
}) | ||
callbackfirstArr = [] | ||
} | ||
|
||
if (!isReady) { | ||
Promise.all([setNetwork(), getServerTime()]).then(function() { | ||
const ARKDEBUG = core.ARKDEBUG | ||
if (config.appkey !== core.ARKAPPID || (ARKDEBUG === 1 && ARKDEBUG !== config.debugMode) || core.ARKUPLOADURL !== config.uploadURL) { | ||
if (core.ARKAPPID) { | ||
resetCore() | ||
} | ||
setCoreParams({ | ||
ARKAPPID: config.appkey, | ||
ARKDEBUG: config.debugMode, | ||
ARKUPLOADURL: config.uploadURL | ||
}) | ||
} | ||
|
||
// onReady函数,sdk生命周期钩子,sdk初次初始化完成(采集数据之前的准备工作已到位) | ||
lifecycleHook.onReady(config) | ||
|
||
callbackArr.forEach(o => { | ||
o.fn.apply(o.fn, o.arg) | ||
}) | ||
}) | ||
isReady = true | ||
if (callbackArr && callbackArr.length) { | ||
callbackArr.forEach(o => { | ||
return o.fn.apply(o.fn, o.arg) | ||
}) | ||
callbackArr = [] | ||
} | ||
} | ||
} | ||
|
||
function ready (callback, isTop?: boolean) { | ||
return function(...args: any[]) { | ||
if (!isReady()) { | ||
const obj = { | ||
fn: callback, | ||
arg: args, | ||
xwhen: getNow() | ||
} | ||
isTop ? callbackfirstArr.push(obj) : callbackArr.push(obj) | ||
} else { | ||
return callback.apply(callback, args) | ||
return callback.apply(callback, args) | ||
} | ||
} | ||
} | ||
|
||
// function ready (callback) { | ||
// return function(...args: any[]) { | ||
|
||
// // 没有获取过NetWork和ServerTime之前先把触发事件存起来,等NetWork和ServerTime获取过后再调用 | ||
// if (!isGetNetWork || !isGetServerTime) { | ||
// callbackArr.push({ | ||
// fn: callback, | ||
// arg: args | ||
// }) | ||
|
||
// if (!isReady) { | ||
// Promise.all([setNetwork(), getServerTime()]).then(function() { | ||
// const ARKDEBUG = core.ARKDEBUG | ||
// if (config.appkey !== core.ARKAPPID || (ARKDEBUG === 1 && ARKDEBUG !== config.debugMode) || core.ARKUPLOADURL !== config.uploadURL) { | ||
// if (core.ARKAPPID) { | ||
// resetCore() | ||
// } | ||
// setCoreParams({ | ||
// ARKAPPID: config.appkey, | ||
// ARKDEBUG: config.debugMode, | ||
// ARKUPLOADURL: config.uploadURL | ||
// }) | ||
// } | ||
|
||
// // onReady函数,sdk生命周期钩子,sdk初次初始化完成(采集数据之前的准备工作已到位) | ||
// lifecycleHook.onReady(config) | ||
|
||
// implementAallbackArr() | ||
// }) | ||
// isReady = true | ||
// } | ||
// } else { | ||
// return callback.apply(callback, args) | ||
// } | ||
// } | ||
// } | ||
|
||
export default ready |