Skip to content

Commit

Permalink
fix(vue-challenges): complete ref family challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Aug 25, 2022
1 parent 499f71a commit b25f88f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vue-challenges/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<script setup lang="ts">
import type { Ref } from 'vue';
import { reactive, ref } from 'vue';
import { isRef, reactive, ref, toRef, unref } from 'vue';
const initial = ref(10);
const count = ref(0);
// Challenge 1: Update ref
function update(value) {
function update(value: number) {
// impl...
count.value = value;
}
/**
* Challenge 2: Check if the `count` is a ref object.
* Make the output be 1
*/
console
.log
console.log(
// impl ? 1 : 0
();
isRef(count) ? 1 : 0
);
/**
* Challenge 3: Unwrap ref
* Make the output be true
*/
function initialCount(value: number | Ref<number>) {
// Make the output be true
console.log(value === 10);
console.log(unref(value) === 10);
}
initialCount(initial);
Expand All @@ -41,7 +42,7 @@ const state = reactive({
foo: 1,
bar: 2,
});
const fooRef = ref(); // change the impl...
const fooRef = ref(toRef(state, 'foo')); // change the impl...
// mutating the ref updates the original
fooRef.value++;
Expand Down

0 comments on commit b25f88f

Please sign in to comment.