2019-07-24 15:55:06 +08:00
|
|
|
import getScrollParent from './dom/getScrollParent'
|
|
|
|
|
|
|
|
const isObject = (o) => {
|
|
|
|
let type = Object.prototype.toString.call(o)
|
|
|
|
return type === '[object Array]' || type === '[object Object]'
|
|
|
|
}
|
|
|
|
|
|
|
|
const _isObject = (o) => {
|
|
|
|
return (typeof o === 'object' || typeof o === 'function') && o !== null
|
|
|
|
}
|
|
|
|
|
|
|
|
const deepClone = (obj) => {
|
|
|
|
if (!isObject(obj)) {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
let isArray = Array.isArray(obj)
|
|
|
|
let cloneObj = isArray ? [] : {}
|
|
|
|
for (let key in obj) {
|
|
|
|
cloneObj[key] = _isObject(obj[key]) ? deepClone(obj[key]) : obj[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloneObj
|
|
|
|
}
|
|
|
|
|
|
|
|
const getObjValue = (obj, keys) => {
|
|
|
|
return keys.reduce((res, n) => (res !== undefined && res[n] !== undefined ? res[n] : null), obj)
|
|
|
|
}
|
|
|
|
|
2019-08-05 16:41:00 +08:00
|
|
|
/**
|
|
|
|
* transfer function into promise
|
|
|
|
*/
|
|
|
|
const funcToPromise = (fn, receiver) => {
|
|
|
|
return (...args) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
fn.apply(receiver, [...args, (err, res) => {
|
|
|
|
return err ? reject(err) : resolve(res)
|
|
|
|
}])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 11:17:04 +08:00
|
|
|
const noopFn = () => {}
|
2019-08-05 16:41:00 +08:00
|
|
|
|
2019-07-11 19:51:59 +08:00
|
|
|
export {
|
2019-07-24 15:55:06 +08:00
|
|
|
getScrollParent,
|
|
|
|
deepClone,
|
2019-08-05 16:41:00 +08:00
|
|
|
getObjValue,
|
2019-08-21 11:17:04 +08:00
|
|
|
funcToPromise,
|
|
|
|
noopFn
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|