Skip to content

Instantly share code, notes, and snippets.

@galvez galvez/timing.client.js

Last active Apr 10, 2019
Embed
What would you like to do?
import Vue from 'vue'
function componentInject(key, setter) {
const installKey = `__component_inject_${key}`
if (Vue[installKey]) {
return
}
Vue[installKey] = true
const componentKey = `$${key}`
const privateKey = `_${key}`
Vue.use(() => {
if (!Vue.prototype.hasOwnProperty(componentKey)) {
Object.defineProperty(Vue.prototype, componentKey, {
get() {
if (!this[privateKey]) {
this[privateKey] = setter(this)
}
return this[privateKey]
}
})
}
})
}
export default function() {
componentInject('every', (component) => {
return (ms) => {
return new Proxy({}, {
get(_, prop) {
return (...args) => {
return setInterval(() => {
component[prop].call(component, ...args)
}, ms)
}
}
})
}
})
componentInject('after', (component) => {
return (ms) => {
return new Proxy({}, {
get(_, prop) {
return (...args) => {
return setTimeout(() => {
component[prop].call(component, ...args)
}, ms)
}
}
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.