Created
January 11, 2021 16:04
-
-
Save themarcba/3340640690d936a8e5bde3e09964609f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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