address feedback

pull/10803/head
Dominic Gannaway 2 years ago
parent 0a3b33f0bd
commit 1c9c386641

@ -3,16 +3,8 @@ import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
import { make_iterable } from './utils.js'; import { make_iterable } from './utils.js';
var methods = [ var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
'difference', var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
'forEach',
'intersection',
'isDisjointFrom',
'isSubsetOf',
'isSupersetOf',
'symmetricDifference',
'union'
];
var inited = false; var inited = false;
@ -26,7 +18,7 @@ export class ReactiveSet extends Set {
#size = source(0); #size = source(0);
/** /**
* @param {Iterable<T> | null | undefined} [value] * @param {T[] | null} [value]
*/ */
constructor(value) { constructor(value) {
super(); super();
@ -35,8 +27,8 @@ export class ReactiveSet extends Set {
if (DEV) new Set(value); if (DEV) new Set(value);
if (value) { if (value) {
for (var element of value) { for (var element of value.keys()) {
this.add(element); this.add(/** @type {T} */ (element));
} }
} }
@ -49,18 +41,28 @@ export class ReactiveSet extends Set {
var proto = ReactiveSet.prototype; var proto = ReactiveSet.prototype;
var set_proto = Set.prototype; var set_proto = Set.prototype;
/**
* @type {string | number}
*/
var method;
for (method of read_methods) {
// @ts-ignore
proto[method] = function (...v) {
get(this.#version);
// @ts-ignore
return set_proto[method].apply(this, v);
};
}
for (var method of methods) { for (method of set_like_methods) {
// @ts-ignore // @ts-ignore
proto[method] = function (...v) { proto[method] = function (...v) {
get(this.#version); get(this.#version);
// @ts-ignore // @ts-ignore
var val = set_proto[method].apply(this, v); var val = set_proto[method].apply(this, v);
// Return a reactive set if the return value is a Set // Return a reactive set if the return value is a Set
if (val instanceof Set) { return new ReactiveSet(/** @type {T[]} */ (val));
return new ReactiveSet(val);
}
return val;
}; };
} }
} }

Loading…
Cancel
Save