Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toRef): issue #855 #859

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(toRef): issue #855
  • Loading branch information
Rigo-m committed Nov 24, 2021
commit 47e3d4782ff5050d2edd8d28c989f2cb324553de
3 changes: 3 additions & 0 deletions src/reactivity/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RefKey } from '../utils/symbols'
import { proxy, isPlainObject, warn, def } from '../utils'
import { reactive, isReactive, shallowReactive } from './reactive'
import { readonlySet } from '../utils/sets'
import { set } from './set'

declare const _refBrand: unique symbol
export interface Ref<T = any> {
Expand Down Expand Up @@ -157,6 +158,8 @@ export function toRef<T extends object, K extends keyof T>(
const v = object[key]
if (isRef<T[K]>(v)) return v

if (!(key in object)) set(object, key, undefined)

return createRef({
get: () => object[key],
set: (v) => (object[key] = v),
Expand Down