-
Notifications
You must be signed in to change notification settings - Fork 344
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: not unwrapping markRaw
objects
#386
Conversation
Thanks for fixing this. Is there any way to undo unwrapping / get the target/underlying object? Something like |
Because of the vue2 limitations, when you change the it('test', ()=>{
const a = {a:1 };
const r = ref(a);
r.value.a = 2
expect(a.a).toBe(2)
}) EDIT: Not sure if I understand your question |
Let me re-phrase it. Automatic unwrapping practically changes object like PS I am okay with Vue 3 only solution - just want to understand what options I have. |
Not currently possible. How do you do that in vue3? |
I don't know - I thought you have an idea. Thanks for the help and sorry for the offtopic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird to have "raw ref" 😅
Anyway, LGTM👍
src/reactivity/unwrap.ts
Outdated
@@ -28,8 +29,12 @@ export function unwrapRefProxy(value: any, map = new WeakMap()) { | |||
|
|||
for (const k of Object.keys(value)) { | |||
const r = value[k] | |||
// don't unwrap or do anything to raw | |||
if (isRaw(r)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that when r
is null
or undefined
, it causes TypeError: Cannot convert undefined or null to object
.
// don't unwrap or do anything to raw | ||
if (isRaw(r)) { | ||
// don't process on falsy or raw | ||
if (!r || isRaw(r)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it better to check falsy inside isRaw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function isRaw(obj: any): boolean {
return !!obj && hasOwn(obj, RawIdentifierKey) && obj[RawIdentifierKey] === RawIdentifier;
}
Not sure if is will help, the idea is if is isRaw
it shouldn't do anything to the object.
even if I add that condition on isRaw
I still need to do unwrap
, since we don't need to process falsy
values
fix #384