-
Notifications
You must be signed in to change notification settings - Fork 341
feat: making all vue2 reactive object be valid isReactive #512
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
Conversation
src/reactivity/reactive.ts
Outdated
| return ( | ||
| (obj && | ||
| typeof obj === 'object' && | ||
| '__ob__' in obj && | ||
| !obj.__ob__.__raw__) || | ||
| false | ||
| ) |
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.
| return ( | |
| (obj && | |
| typeof obj === 'object' && | |
| '__ob__' in obj && | |
| !obj.__ob__.__raw__) || | |
| false | |
| ) | |
| return Boolean(obj?.__ob__ && !obj.__bo__?.__raw__) |
src/reactivity/reactive.ts
Outdated
|
|
||
| export function isRaw(obj: any): boolean { | ||
| return rawSet.has(obj) | ||
| return obj && typeof obj === 'object' && '__ob__' in obj && obj.__ob__.__raw__ |
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.
| return obj && typeof obj === 'object' && '__ob__' in obj && obj.__ob__.__raw__ | |
| return Boolean(obj?.__ob__?.__raw__) |
src/reactivity/reactive.ts
Outdated
| const ob = (observed as any).__ob__ | ||
|
|
||
| for (const key of Object.keys(obj)) { | ||
| // @ts-ignore |
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.
Do we need this? I think we can make the function arg to (obj: any): T and get rid of those as any then.
src/reactivity/reactive.ts
Outdated
|
|
||
| return (observed as any).__ob__.value || observed | ||
| return ( | ||
| ((observed as any).__ob__ && (observed as any).__ob__.value) || observed |
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.
| ((observed as any).__ob__ && (observed as any).__ob__.value) || observed | |
| (observed as any)?.__ob__?.value) || observed |
src/mixin.ts
Outdated
| // mark props | ||
| markReactive(props) | ||
| // fake reactive for `toRefs(props)` | ||
| def(props, '__props_reactive__', true) |
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.
Let's put __props_reactive__ inside src/utils/symbols.ts instead of a magic string 😄
fix #517
Simplifying the logic of
isReactivenow every valid reactive v2 object will be a valid isReactive object.The only issue with this is
isReactive(obj) === truewon't mean auto-unwrapping