Skip to content

Instantly share code, notes, and snippets.

@themarcba
Created January 11, 2021 16:04
Show Gist options
  • Save themarcba/3340640690d936a8e5bde3e09964609f to your computer and use it in GitHub Desktop.
Save themarcba/3340640690d936a8e5bde3e09964609f to your computer and use it in GitHub Desktop.
const { computed, ref, effect } = require('@vue/reactivity')
let users = ref([])
let onlineUsers = computed(() => {
return users.value.filter((user) => user.status === 'online')
})
effect(() => {
console.log('# of online users changed', onlineUsers.value.length)
})
setInterval(() => {
const status = Math.random() > 0.5 ? 'online' : 'offline'
console.log(`adding ${status} user`)
users.value.push({ status })
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment