Set, Date, URL

better-snapshot
Rich Harris 8 months ago
parent ee702d153f
commit 1602ae62bd

@ -1,3 +1,4 @@
import { STATE_SNAPSHOT_SYMBOL } from '../internal/client/constants.js';
import { source, set } from '../internal/client/reactivity/sources.js'; import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
@ -99,4 +100,8 @@ export class ReactiveDate extends Date {
super(...values); super(...values);
this.#init(); this.#init();
} }
[STATE_SNAPSHOT_SYMBOL]() {
return new Date(get(this.#raw_time));
}
} }

@ -2,6 +2,8 @@ import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js'; import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
import { map } from './utils.js'; import { map } from './utils.js';
import { STATE_SNAPSHOT_SYMBOL } from '../internal/client/constants.js';
import { snapshot } from '../internal/client/reactivity/snapshot.js';
var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf']; var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union']; var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
@ -149,4 +151,9 @@ export class ReactiveSet extends Set {
get size() { get size() {
return get(this.#size); return get(this.#size);
} }
/** @param {boolean} deep */
[STATE_SNAPSHOT_SYMBOL](deep) {
return new Set(map(this.keys(), (key) => snapshot(key, deep), 'Set Iterator'));
}
} }

@ -1,3 +1,4 @@
import { STATE_SNAPSHOT_SYMBOL } from '../internal/client/constants.js';
import { source, set } from '../internal/client/reactivity/sources.js'; import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
@ -150,6 +151,10 @@ export class ReactiveURL extends URL {
toJSON() { toJSON() {
return this.href; return this.href;
} }
[STATE_SNAPSHOT_SYMBOL]() {
return new URL(this.href);
}
} }
export class ReactiveURLSearchParams extends URLSearchParams { export class ReactiveURLSearchParams extends URLSearchParams {

Loading…
Cancel
Save