Skip to content

Instantly share code, notes, and snippets.

View themarcba's full-sized avatar

Marc Backes themarcba

View GitHub Profile
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)
})
@themarcba
themarcba / README.txt
Last active May 8, 2024 03:31
Vue.js Global - Vue 3 Reactivity Under The Hood
This is an addition to my Vue.js Global 2020 talk about Vue 3 Reactivity.
Some people asked for the slides. You can find them here:
https://marcbackes.com/d8qaLT
your_collection.find({
your_date_field: {
$gte: ISODate('2020-07-01T00:00:00.000Z'), // From
$lt: ISODate('2020-07-31T23:59:00.000Z'), // Until
},
})
@themarcba
themarcba / vuejs-like-mini-framework.html
Created May 23, 2020 12:24
This is the click counter example for a blog post I wrote about creating your own mini-Vue.js. https://marc.dev/blog/vue-from-scratch-part-5
<style>
* {
user-select: none;
}
body {
margin: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#app {
height: 100vh;
@themarcba
themarcba / vuejs-like-reactive-state.html
Last active February 5, 2024 11:52
Vue.js-like reactive state
<script>
let activeEffect
class Dep {
subscribers = new Set()
depend() {
if (activeEffect) this.subscribers.add(activeEffect)
}
notify() {
this.subscribers.forEach((sub) => sub())
@themarcba
themarcba / vuejs-like-dependency.html
Last active February 5, 2024 11:51
Vue.js-like Reactive Dependency
<script>
let activeEffect
class Dep {
// Initialize the value of the reactive dependency
constructor(value) {
this._value = value
this.subscribers = new Set()
}
@themarcba
themarcba / vdom-finished.html
Last active April 20, 2024 03:37
Vue.js-like Virtual DOM
<div id="app"></div>
<script>
// Create virtual node
function h(tag, props, children) {
// Return the virtual node
return {
tag,
props,
children,
}
const timedResolve = name => {
return new Promise(resolve =>
setTimeout(() => {
console.log(name)
resolve()
}, 500 * Math.random()),
)
}
Promise.all([
window.App.startLocalMedia(video, screencapture, audioonly, receiveonly, null, null).then(
function(o) {
if (!receiveonly) {
fm.liveswitch.Log.info('Started local media.')
}
fm.liveswitch.Log.info('Registering...')
window.App.joinAsync(_this.incomingMessage, _this.peerLeft, _this.peerJoined, _this.clientRegistered).then(
function(o) {
// Transforms a string to either upper or lowercase, depending which is dominant
// code => code
// coDe => code
// CoDE => CODE
// etc.
const transform = input => {
const lower = [...input].reduce((count, char) => {
return char == char.toLowerCase() ? count + 1 : count
}, 0)
return lower / input.length >= .5 ? input.toLowerCase() : input.toUpperCase()