make reactive set better

pull/10803/head
Dominic Gannaway 2 years ago
parent 279f1ca012
commit 0a3b33f0bd

@ -3,7 +3,7 @@ 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 read = [ var methods = [
'difference', 'difference',
'forEach', 'forEach',
'intersection', 'intersection',
@ -50,12 +50,17 @@ export class ReactiveSet extends Set {
var proto = ReactiveSet.prototype; var proto = ReactiveSet.prototype;
var set_proto = Set.prototype; var set_proto = Set.prototype;
for (var method of read) { for (var method of methods) {
// @ts-ignore // @ts-ignore
proto[method] = function (...v) { proto[method] = function (...v) {
get(this.#version); get(this.#version);
// @ts-ignore // @ts-ignore
return 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
if (val instanceof Set) {
return new ReactiveSet(val);
}
return val;
}; };
} }
} }

Loading…
Cancel
Save