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: the reactive set supports the difference, intersection, isDisjointFrom, isSubsetOf, isSupersetOf, and symmetricDifference methods #11399

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

linzhe141
Copy link
Contributor

@linzhe141 linzhe141 commented Jul 19, 2024

close #11398

It requires Node v22

Copy link

github-actions bot commented Jul 19, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+229 B) 38 kB (+87 B) 34.3 kB (+105 B)
vue.global.prod.js 159 kB (+229 B) 58 kB (+91 B) 51.5 kB (+40 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.6 kB (+229 B) 18.9 kB (+90 B) 17.2 kB (+28 B)
createApp 55.2 kB (+229 B) 21.4 kB (+88 B) 19.5 kB (+97 B)
createSSRApp 59.2 kB (+229 B) 23.1 kB (+89 B) 21 kB (+80 B)
defineCustomElement 60 kB (+229 B) 22.9 kB (+99 B) 20.9 kB (+12 B)
overall 68.9 kB (+229 B) 26.4 kB (+88 B) 24 kB (+21 B)

@sxzz
Copy link
Member

sxzz commented Jul 19, 2024

Could you please add a unit test?

@linzhe141
Copy link
Contributor Author

linzhe141 commented Jul 19, 2024

Could you please add a unit test?

这里很多的api,好像都不支持

image

好像node22才能支持这些新增的api,所以单测没过

…tFrom, isSubsetOf, isSupersetOf, and symmetricDifference` methods
@linzhe141 linzhe141 changed the title feat(reactivity): set supurts intersection feat: the reactive set supports the difference, intersection, isDisjointFrom, isSubsetOf, isSupersetOf, and symmetricDifference methods Jul 19, 2024
@@ -173,6 +173,24 @@ function createForEach(isReadonly: boolean, isShallow: boolean) {
}
}

function createSetProtoMethod(method: TriggerOpTypes) {
return function (this: SetTypes, value: unknown, _isShallow = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is anything passing the _isShallow flag? Is it actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is really not necessary

if (!hadKey) {
// @ts-expect-error
result = target[method](value)
trigger(target, method, value, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be tracking rather than triggering?

These methods don't currently track correctly inside reactive effects. e.g.:

The unit tests aren't really testing this, as the effect isn't wrapped around the method call.

I haven't confirmed this, but I suspect these methods could reuse TrackOpTypes.ITERATE.

}
const target = toRaw(this)
const proto = getProto(target)
const hadKey = proto.has.call(target, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this is for. The name value here is a bit misleading, as it refers to the other set. Why do we need to check whether one set is inside the other? This seems to break the methods if one set contains the other:

@linzhe141 linzhe141 marked this pull request as draft July 22, 2024 01:11
@linzhe141 linzhe141 marked this pull request as ready for review July 22, 2024 11:55
@edison1105 edison1105 added ✨ feature request New feature or request version: minor 🛑 on hold This PR can't be merged until other work is finished ready for review This PR requires more reviews labels Aug 28, 2024
Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

I think there's a lot of redundancy in this implementation that can be removed by taking a similar approach to createIterableMethod. Specifically:

  • The method argument for createSetProtoMethod should just be a string, rather than a TriggerOpTypes.
  • I don't think we need to add any new values to TriggerOpTypes for this, they're just string method names.
  • Much like for iteratorMethods, I think these can all be added in a loop, rather than duplicating all the code for each method.

The refactoring in #12152 reduced the amount of duplication in createInstrumentations. Once the latest main is merged into this branch it shouldn't be necessary to repeat the logic 4 times

Copy link

pkg-pr-new bot commented Oct 12, 2024

Open in Stackblitz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@11399

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@11399

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@11399

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@11399

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@11399

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@11399

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@11399

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@11399

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@11399

vue

pnpm add https://pkg.pr.new/vue@11399

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@11399

commit: 63d5d8f

@linzhe141 linzhe141 marked this pull request as draft October 12, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛑 on hold This PR can't be merged until other work is finished ready for review This PR requires more reviews ✨ feature request New feature or request version: minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cannot call Set#intersection for set with Proxy
4 participants