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

feat: throw error if the read-only property is tried to change #749

Merged
merged 3 commits into from
Jun 24, 2018

Conversation

38elements
Copy link
Contributor

@38elements 38elements commented Jun 23, 2018

This makes the read-only property to throw error if the read-only property is tried to change.
This is related to #747.


constructor (wrappers: Array<Wrapper | VueWrapper>) {
this.wrappers = wrappers || []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrappers is always an Array object.

// $FlowIgnore
Object.defineProperty(this, 'wrappers', {
get: () => wrappers,
set: () => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw an error to tell the users it's read only.

I realize this isn't part of this PR, but I think we should do the same for vnode, and element.

Copy link
Contributor Author

@38elements 38elements Jun 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing out.
I will change them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vnode is undocmumented.
Should vnode is added to document?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. No I don't think it needs to be documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reply.
I think so too.

@38elements 38elements changed the title feat: change WrapperArray.wrappers and WrapperArray.length to read-only feat: throw error if the read-only property is tried to change Jun 23, 2018
@38elements 38elements changed the title feat: throw error if the read-only property is tried to change feat: throw error if the read-only property is tried to change Jun 23, 2018
@@ -11,17 +12,17 @@ export default class VueWrapper extends Wrapper implements BaseWrapper {
// $FlowIgnore : issue with defineProperty
Object.defineProperty(this, 'vnode', {
get: () => vm._vnode,
set: () => {}
set: () => throwError(`VueWrapper.vnode is read-only`)
Copy link
Member

@eddyerburgh eddyerburgh Jun 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a Wrapper or a VueWrapper, I think just go with:

I don't think we need to distinguish between a wrapper and a VueWrapper, I think just go with wrapper:

wrapper.vnode is read-only

@@ -667,7 +668,7 @@ export default class Wrapper implements BaseWrapper {
})

// $FlowIgnore : Problem with possibly null this.vm
this.vnode = this.vm._vnode
this._vnode = this.vm._vnode
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyerburgh
There is a problem.
This line did not make error at #748.
Is this line necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can flowignore it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since vueWrapper.vnode is read-only, I removed this line.

@38elements
Copy link
Contributor Author

I changed them.

@@ -5,12 +5,21 @@ import type VueWrapper from './vue-wrapper'
import { throwError, warn } from 'shared/util'

export default class WrapperArray implements BaseWrapper {
wrappers: Array<Wrapper | VueWrapper>;
length: number;
+wrappers: Array<Wrapper | VueWrapper>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool I didn't know you could specify read only with flow 👍

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@eddyerburgh eddyerburgh merged commit fb46268 into vuejs:dev Jun 24, 2018
@38elements 38elements deleted the wrapperarray branch June 24, 2018 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants