Subscribe on changes!

in function reactive, i find useless code

avatar
Jan 6th 2021

What problem does this feature solve?

i find reactive function declare belows export function reactive(target: object) { // if trying to observe a readonly proxy, return the readonly version. if (target && (target as Target)[ReactiveFlags.IS_READONLY]) { return target } return createReactiveObject( target, false, mutableHandlers, mutableCollectionHandlers ) }

i think if (target && (target as Target)[ReactiveFlags.IS_READONLY]) { return target } is useless, want to delete

What does the proposed API look like?

export function reactive(target: object) { return createReactiveObject( target, false, mutableHandlers, mutableCollectionHandlers ) }

avatar
Jan 6th 2021

The use of that piece of code is explained in the comment directly above it.

avatar
Jan 7th 2021

The use of that piece of code is explained in the comment directly above it.

i think the code above i mentinoned is useless, because in function createReactiveObject will solve the situation that if trying to observe a readonly proxy, return the readonly version, becasuse in createReactiveObject , except readonly() on a reactive object, as long as the target is a proxy, the function createReactiveObject will return the target, so the code is repleat, and when i delete the code above i mentioned, when i run 'npm test', it can pass and has no errors