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

test(reactivity): support passing object with only one get property #9122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chenfan0
Copy link
Contributor

@chenfan0 chenfan0 commented Sep 3, 2023

No description provided.

@github-actions
Copy link

github-actions bot commented Sep 3, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 85.8 kB 32.6 kB 29.5 kB
vue.global.prod.js 132 kB 49.3 kB 44.3 kB

Usages

Name Size Gzip Brotli
createApp 47.9 kB 18.8 kB 17.2 kB
createSSRApp 50.6 kB 19.9 kB 18.2 kB
defineCustomElement 50.3 kB 19.6 kB 17.9 kB
overall 61.2 kB 23.7 kB 21.6 kB

Copy link
Member

@sxzz sxzz left a comment

Choose a reason for hiding this comment

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

Why? It's necessary.

@jacekkarczmarczyk
Copy link
Contributor

If it's necessary and tests still pass after removing it maybe there should be a test for this?

@sxzz
Copy link
Member

sxzz commented Sep 3, 2023

Yes. Add the case:

import { computed, isReadonly } from 'vue'

const a = computed(() => 1)
// @ts-expect-error
const b = computed({ get: () => 1 })

console.log(isReadonly(a), isReadonly(b))
// Both should be true

@chenfan0
Copy link
Contributor Author

chenfan0 commented Sep 3, 2023

Yes. Add the case:

import { computed, isReadonly } from 'vue'

const a = computed(() => 1)
// @ts-expect-error
const b = computed({ get: () => 1 })

console.log(isReadonly(a), isReadonly(b))
// Both should be true

If the ts type is strictly adhered to, then this setter is unnecessary. If it is not strictly adhered to, should the key of the WritableComputedOptions<T> be changed to optional?

@sxzz
Copy link
Member

sxzz commented Sep 3, 2023

We encourage users to use computed(() => 1), but if they're using computed({ get: () => 1 }), we cannot break the existing app either.

I think keeping existing cases is for greater robustness.

@chenfan0 chenfan0 force-pushed the refactor/remove-setter branch from 1aba386 to b218426 Compare September 4, 2023 04:53
@chenfan0 chenfan0 changed the title refactor: remove unnecessary setter test(reactivity): support passing object with only one get property Sep 4, 2023
@haoqunjiang haoqunjiang added the 🧹 p1-chore Priority 1: this doesn't change code behavior. label Apr 1, 2024
@@ -151,6 +151,14 @@ describe('reactivity/computed', () => {
expect(n.value).toBe(-1)
})

it('should support passing object with only one get property', () => {
const a = computed(() => 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the scenario tested by a is already tested by it('should be readonly'. I think that part can be removed here.

I also wonder whether the test for b should just be merged into it('should be readonly'? Or, if not, maybe move this test case to be next to that one?

@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior. ready to merge The PR is ready to be merged.
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

6 participants