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

Keyed collections #962

Closed
wants to merge 77 commits into from
Closed

Conversation

overthemike
Copy link
Collaborator

Related Bug Reports or Discussions

#943
Fixes #
N/A

Summary

Created new implementation for proxyMap and proxySet. Added benchmarks and a few new tests.

Check List

  • [ x ] pnpm run prettier for formatting code and docs

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

this is something i feel "solid" except for one case which we need to cover later.

src/vanilla/utils/proxyMap-indexMap.ts Show resolved Hide resolved
src/vanilla/utils/proxyMap-indexMap.ts Outdated Show resolved Hide resolved
nextIndex = data.length

const vObject: InternalProxyObject<K, V> = {
data,
Copy link
Member

Choose a reason for hiding this comment

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

We need this not to rely on data.length.

Suggested change
data,
data,
nextIndex,

const k = maybeProxify(key)
if (!indexMap.has(k) && !isProxy(this)) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.data.length
Copy link
Member

Choose a reason for hiding this comment

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

and this.

Suggested change
this.data.length
this.nextIndex

Comment on lines +47 to +49
if (this.data[index] !== undefined) {
return this.data[index]![1]
}
Copy link
Member

Choose a reason for hiding this comment

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

let's simplify unless there's a serious issue.

Suggested change
if (this.data[index] !== undefined) {
return this.data[index]![1]
}
return this.data[index]![1]

src/vanilla/utils/proxyMap-indexMap.ts Outdated Show resolved Hide resolved
src/vanilla/utils/proxyMap-indexMap.ts Outdated Show resolved Hide resolved
const isProxy = (x: any) => proxyStateMap.has(x)

type InternalProxyObject<K, V> = Map<K, V> & {
data: Array<[K, V | undefined]>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data: Array<[K, V | undefined]>
data: Array<[K, V | undefined]>
nextIndex: number


type InternalProxyObject<K, V> = Map<K, V> & {
data: Array<[K, V | undefined]>
size: number
Copy link
Member

Choose a reason for hiding this comment

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

just curious: do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The type definition? I could declare it when I create vObject below if you prefer that

Copy link
Member

Choose a reason for hiding this comment

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

I mean I thought Map<K, V> type already includes size property.


Object.defineProperties(proxiedObject, {
size: { enumerable: false },
data: { enumerable: false },
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data: { enumerable: false },
nextIndex: { enumerable: false },

@dai-shi
Copy link
Member

dai-shi commented Oct 12, 2024

please create a new branch in this repo and open a new pr.

@dai-shi dai-shi closed this Oct 12, 2024
@overthemike overthemike deleted the keyed-collections branch October 19, 2024 14:23
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