29 lines
709 B
JavaScript
29 lines
709 B
JavaScript
import traverse from 'traverse'
|
|
import _ from '@uci-utils/type'
|
|
import clone from 'clone'
|
|
|
|
function bindFuncs (pfuncs,site) {
|
|
let funcs = clone(pfuncs)
|
|
if (!site) site=this
|
|
if(_.isArray(funcs)) {
|
|
funcs.forEach(function (entry,index) {
|
|
if(_.isFunction(entry)) funcs[index] = entry.bind(site)
|
|
})
|
|
return funcs
|
|
}
|
|
if(_.isPlainObject(funcs)) {
|
|
traverse(funcs).forEach(function (func) {
|
|
// console.log(this.path)
|
|
if(_.isFunction(func)) {
|
|
// console.log('function',this.path)
|
|
this.update(func.bind(site))
|
|
}
|
|
})
|
|
return funcs
|
|
}
|
|
throw('bindFuncs: must be array or plain object of functions')
|
|
}
|
|
|
|
export default bindFuncs
|
|
export { bindFuncs }
|