This file contains 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
let currentListener = undefined | |
const createEffect = (callback) => { | |
currentListener = callback | |
callback() | |
currentListener = undefined | |
} | |
// Use case | |
createEffect(() => { |
This file contains 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
import { ref, computed } from 'vue' | |
const A = ref(1) | |
const B = ref(2) | |
const C = computed(() => A.value + B.value) | |
A.value = 2 |
This file contains 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
import { ref, watchEffect } from 'vue' | |
const A = ref(1) | |
const B = ref(2) | |
const C = ref() | |
watchEffect(() => { | |
C.value = A.value + B.value | |
}) |
This file contains 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
let A = 1 | |
let B = 2 | |
let C | |
function update() { | |
C = A + B | |
} | |
whenDepsChange(update) |
This file contains 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
console.log(myProxy.message1) // "world" | |
console.log(myProxy.message2) // "world" |
This file contains 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 target = { | |
message1: "hello", | |
message2: "everyone" | |
}; | |
const handler = { | |
get(target, prop, receiver) { | |
return "world"; | |
} | |
}; |
This file contains 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 myName = ref('Cassie') | |
myName.value = 'Vanessa' |
This file contains 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
myFriendList.list.push("Rosalie") |
This file contains 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 myFriendList = { | |
list: ["Pauline", "Ségoline", "Christina"], | |
get lastNewFriend() { | |
return this.list[this.list.length - 1] | |
}, | |
set addNewFriend(newFriend) { | |
this.list.push(newFriend) | |
} | |
} |
This file contains 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
whenDepsChange(update) |
NewerOlder