-
Notifications
You must be signed in to change notification settings - Fork 143
update map/set constructor to match TypeScript's... mostly #459
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@solid-primitives/map": patch | ||
| "@solid-primitives/set": patch | ||
| --- | ||
|
|
||
| Update `ReactiveSet`/`ReactiveMap` constructors to allow passing any iterable as the initial value. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ export class ReactiveMap<K, V> extends Map<K, V> { | |
| #keyTriggers = new TriggerCache<K | typeof $KEYS>(); | ||
| #valueTriggers = new TriggerCache<K>(); | ||
|
|
||
| constructor(initial?: [K, V][]) { | ||
| constructor(initial?: Iterable<readonly [K, V]> | null) { | ||
| super(); | ||
| if (initial) for (const v of initial) super.set(v[0], v[1]); | ||
| } | ||
|
|
@@ -127,7 +127,7 @@ export class ReactiveWeakMap<K extends object, V> extends WeakMap<K, V> { | |
| #keyTriggers = new TriggerCache<K>(WeakMap); | ||
| #valueTriggers = new TriggerCache<K>(WeakMap); | ||
|
|
||
| constructor(initial?: [K, V][]) { | ||
| constructor(initial?: Iterable<readonly [K, V]> | null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c.f. https://github.com/microsoft/TypeScript/blob/main/src/lib/es2015.iterable.d.ts#LL147C40-L147C67 Note that TypeScript doesn't support undefined or null; I think this is a bug because the spec says:
The TS PR making "Map constructor argument optional and nullable" didn't include
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we are doing a |
||
| super(); | ||
| if (initial) for (const v of initial) super.set(v[0], v[1]); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ const $KEYS = Symbol("track-keys"); | |
| export class ReactiveSet<T> extends Set<T> { | ||
| #triggers = new TriggerCache<T | typeof $KEYS>(); | ||
|
|
||
| constructor(values?: readonly T[] | null) { | ||
| constructor(values?: Iterable<T> | null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c.f. https://github.com/microsoft/TypeScript/blob/main/src/lib/es2015.iterable.d.ts#LL189C21-L189C42 I'm not sure why this is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| super(); | ||
| if (values) for (const v of values) super.add(v); | ||
| } | ||
|
|
@@ -94,7 +94,7 @@ export class ReactiveSet<T> extends Set<T> { | |
| export class ReactiveWeakSet<T extends object> extends WeakSet<T> { | ||
| #triggers = new TriggerCache<T>(WeakMap); | ||
|
|
||
| constructor(values?: readonly T[] | null) { | ||
| constructor(values?: Iterable<T> | null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/microsoft/TypeScript/blob/main/src/lib/es2015.iterable.d.ts#LL195C47-L195C60 The above comments also apply here - in particular the
|
||
| super(); | ||
| if (values) for (const v of values) super.add(v); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.f. https://github.com/microsoft/TypeScript/blob/main/src/lib/es2015.iterable.d.ts#LL141C24-L141C59