Skip to content

Instantly share code, notes, and snippets.

@anteriovieira
Created March 3, 2017 16:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anteriovieira/b089f3fe6a2b9bfe1d904f319744e4f0 to your computer and use it in GitHub Desktop.
Save anteriovieira/b089f3fe6a2b9bfe1d904f319744e4f0 to your computer and use it in GitHub Desktop.
VueJs
var subscribers = []
var activeJob = null
var a = 3
var state = {
get a () {
if(subscribers.indexOf(activeJob) < 0){
subscribers.push(activeJob)
}
return a
},
set a (newValue){
a = newValue
subscribers.forEach(job => job())
}
}
var autorun = update => {
function job() {
activeJob = job
update()
activeJob = null
}
job()
}
autorun(() => {
console.log((state.a * 10))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment