You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
457 B
22 lines
457 B
|
|
let datas = {}
|
|
|
|
export function data(name, callback) {
|
|
datas[name] = callback
|
|
}
|
|
|
|
export function injectDataProviders(obj, context) {
|
|
Object.entries(datas).forEach(([name, callback]) => {
|
|
Object.defineProperty(obj, name, {
|
|
get() {
|
|
return (...args) => {
|
|
return callback.bind(context)(...args)
|
|
}
|
|
},
|
|
|
|
enumerable: false,
|
|
})
|
|
})
|
|
|
|
return obj
|
|
}
|
|
|