Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-jobs-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

breaking: rename `svelte/reactivity` helpers to include `Svelte` prefix
4 changes: 2 additions & 2 deletions packages/svelte/src/reactivity/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const write = [

var inited = false;

export class ReactiveDate extends Date {
export class SvelteDate extends Date {
#raw_time = source(super.getTime());

// We init as part of the first instance so that we can treeshake this class
#init() {
if (!inited) {
inited = true;
const proto = ReactiveDate.prototype;
const proto = SvelteDate.prototype;
const date_proto = Date.prototype;

for (const method of read) {
Expand Down
33 changes: 29 additions & 4 deletions packages/svelte/src/reactivity/index-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
export { ReactiveDate as Date } from './date.js';
export { ReactiveSet as Set } from './set.js';
export { ReactiveMap as Map } from './map.js';
export { ReactiveURL as URL, ReactiveURLSearchParams as URLSearchParams } from './url.js';
export { SvelteDate } from './date.js';
export { SvelteSet } from './set.js';
export { SvelteMap } from './map.js';
export { SvelteURL, SvelteURLSearchParams } from './url.js';

/** @deprecated Use `SvelteDate` instead */
export function Date() {
throw new Error('Date has been removed, use SvelteDate instead.');
}

/** @deprecated Use `SvelteSet` instead */
export function Set() {
throw new Error('Set has been removed, use SvelteSet instead.');
}

/** @deprecated Use `SvelteMap` instead */
export function Map() {
throw new Error('Map has been removed, use SvelteMap instead.');
}

/** @deprecated Use `SvelteURL` instead */
export function URL() {
throw new Error('URL has been removed, use SvelteURL instead.');
}

/** @deprecated Use `SvelteURLSearchParams` instead */
export function URLSearchParams() {
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
}
35 changes: 30 additions & 5 deletions packages/svelte/src/reactivity/index-server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
export const Date = globalThis.Date;
export const Set = globalThis.Set;
export const Map = globalThis.Map;
export const URL = globalThis.URL;
export const URLSearchParams = globalThis.URLSearchParams;
export const SvelteDate = globalThis.Date;
export const SvelteSet = globalThis.Set;
export const SvelteMap = globalThis.Map;
export const SvelteURL = globalThis.URL;
export const SvelteURLSearchParams = globalThis.URLSearchParams;

/** @deprecated Use `SvelteDate` instead */
export function Date() {
throw new Error('Date has been removed, use SvelteDate instead.');
}

/** @deprecated Use `SvelteSet` instead */
export function Set() {
throw new Error('Set has been removed, use SvelteSet instead.');
}

/** @deprecated Use `SvelteMap` instead */
export function Map() {
throw new Error('Map has been removed, use SvelteMap instead.');
}

/** @deprecated Use `SvelteURL` instead */
export function URL() {
throw new Error('URL has been removed, use SvelteURL instead.');
}

/** @deprecated Use `SvelteURLSearchParams` instead */
export function URLSearchParams() {
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
}
2 changes: 1 addition & 1 deletion packages/svelte/src/reactivity/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { increment } from './utils.js';
* @template V
* @extends {Map<K, V>}
*/
export class ReactiveMap extends Map {
export class SvelteMap extends Map {
/** @type {Map<K, import('#client').Source<number>>} */
#sources = new Map();
#version = source(0);
Expand Down
18 changes: 9 additions & 9 deletions packages/svelte/src/reactivity/map.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
import { flushSync } from '../index-client.js';
import { ReactiveMap } from './map.js';
import { SvelteMap } from './map.js';
import { assert, test } from 'vitest';

test('map.values()', () => {
const map = new ReactiveMap([
const map = new SvelteMap([
[1, 1],
[2, 2],
[3, 3],
Expand Down Expand Up @@ -65,7 +65,7 @@ test('map.values()', () => {
});

test('map.get(...)', () => {
const map = new ReactiveMap([
const map = new SvelteMap([
[1, 1],
[2, 2],
[3, 3]
Expand Down Expand Up @@ -101,7 +101,7 @@ test('map.get(...)', () => {
});

test('map.has(...)', () => {
const map = new ReactiveMap([
const map = new SvelteMap([
[1, 1],
[2, 2],
[3, 3]
Expand Down Expand Up @@ -148,7 +148,7 @@ test('map.has(...)', () => {
});

test('map.forEach(...)', () => {
const map = new ReactiveMap([
const map = new SvelteMap([
[1, 1],
[2, 2],
[3, 3]
Expand All @@ -169,7 +169,7 @@ test('map.forEach(...)', () => {
});

test('map.delete(...)', () => {
const map = new ReactiveMap([
const map = new SvelteMap([
[1, 1],
[2, 2],
[3, 3]
Expand All @@ -182,7 +182,7 @@ test('map.delete(...)', () => {
});

test('map handling of undefined values', () => {
const map = new ReactiveMap();
const map = new SvelteMap();

const log: any = [];

Expand All @@ -208,7 +208,7 @@ test('map handling of undefined values', () => {
});

test('not invoking reactivity when value is not in the map after changes', () => {
const map = new ReactiveMap([[1, 1]]);
const map = new SvelteMap([[1, 1]]);

const log: any = [];

Expand Down Expand Up @@ -236,5 +236,5 @@ test('not invoking reactivity when value is not in the map after changes', () =>
});

test('Map.instanceOf', () => {
assert.equal(new ReactiveMap() instanceof Map, true);
assert.equal(new SvelteMap() instanceof Map, true);
});
6 changes: 3 additions & 3 deletions packages/svelte/src/reactivity/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var inited = false;
* @template T
* @extends {Set<T>}
*/
export class ReactiveSet extends Set {
export class SvelteSet extends Set {
/** @type {Map<T, import('#client').Source<boolean>>} */
#sources = new Map();
#version = source(0);
Expand Down Expand Up @@ -41,7 +41,7 @@ export class ReactiveSet extends Set {
#init() {
inited = true;

var proto = ReactiveSet.prototype;
var proto = SvelteSet.prototype;
var set_proto = Set.prototype;

for (const method of read_methods) {
Expand All @@ -59,7 +59,7 @@ export class ReactiveSet extends Set {
get(this.#version);
// @ts-ignore
var set = /** @type {Set<T>} */ (set_proto[method].apply(this, v));
return new ReactiveSet(set);
return new SvelteSet(set);
};
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/svelte/src/reactivity/set.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
import { flushSync } from '../index-client.js';
import { ReactiveSet } from './set.js';
import { SvelteSet } from './set.js';
import { assert, test } from 'vitest';

test('set.values()', () => {
const set = new ReactiveSet([1, 2, 3, 4, 5]);
const set = new SvelteSet([1, 2, 3, 4, 5]);

const log: any = [];

Expand Down Expand Up @@ -36,7 +36,7 @@ test('set.values()', () => {
});

test('set.has(...)', () => {
const set = new ReactiveSet([1, 2, 3]);
const set = new SvelteSet([1, 2, 3]);

const log: any = [];

Expand Down Expand Up @@ -79,7 +79,7 @@ test('set.has(...)', () => {
});

test('set.delete(...)', () => {
const set = new ReactiveSet([1, 2, 3]);
const set = new SvelteSet([1, 2, 3]);

assert.equal(set.delete(3), true);
assert.equal(set.delete(3), false);
Expand All @@ -88,7 +88,7 @@ test('set.delete(...)', () => {
});

test('set.forEach()', () => {
const set = new ReactiveSet([1, 2, 3, 4, 5]);
const set = new SvelteSet([1, 2, 3, 4, 5]);

const log: any = [];

Expand All @@ -108,7 +108,7 @@ test('set.forEach()', () => {
});

test('not invoking reactivity when value is not in the set after changes', () => {
const set = new ReactiveSet([1, 2]);
const set = new SvelteSet([1, 2]);

const log: any = [];

Expand Down Expand Up @@ -155,5 +155,5 @@ test('not invoking reactivity when value is not in the set after changes', () =>
});

test('Set.instanceOf', () => {
assert.equal(new ReactiveSet() instanceof Set, true);
assert.equal(new SvelteSet() instanceof Set, true);
});
6 changes: 3 additions & 3 deletions packages/svelte/src/reactivity/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { increment } from './utils.js';

const REPLACE = Symbol();

export class ReactiveURL extends URL {
export class SvelteURL extends URL {
#protocol = source(super.protocol);
#username = source(super.username);
#password = source(super.password);
#hostname = source(super.hostname);
#port = source(super.port);
#pathname = source(super.pathname);
#hash = source(super.hash);
#searchParams = new ReactiveURLSearchParams();
#searchParams = new SvelteURLSearchParams();

/**
* @param {string | URL} url
Expand Down Expand Up @@ -153,7 +153,7 @@ export class ReactiveURL extends URL {
}
}

export class ReactiveURLSearchParams extends URLSearchParams {
export class SvelteURLSearchParams extends URLSearchParams {
#version = source(0);

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/svelte/src/reactivity/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
import { flushSync } from '../index-client.js';
import { ReactiveURL, ReactiveURLSearchParams } from './url.js';
import { SvelteURL, SvelteURLSearchParams } from './url.js';
import { assert, test } from 'vitest';

test('url.hash', () => {
const url = new ReactiveURL('http://google.com');
const url = new SvelteURL('http://google.com');
const log: any = [];

const cleanup = effect_root(() => {
Expand Down Expand Up @@ -32,7 +32,7 @@ test('url.hash', () => {
});

test('url.searchParams', () => {
const url = new ReactiveURL('https://svelte.dev?foo=bar&t=123');
const url = new SvelteURL('https://svelte.dev?foo=bar&t=123');
const log: any = [];

const cleanup = effect_root(() => {
Expand Down Expand Up @@ -78,7 +78,7 @@ test('url.searchParams', () => {
});

test('URLSearchParams', () => {
const params = new ReactiveURLSearchParams();
const params = new SvelteURLSearchParams();
const log: any = [];

const cleanup = effect_root(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { Date } from 'svelte/reactivity';
import { SvelteDate } from 'svelte/reactivity';

let date = new Date('2024-02-23T15:00:00Z');
let date = new SvelteDate('2024-02-23T15:00:00Z');
</script>

<div>getSeconds: {date.getUTCSeconds()}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { Map } from 'svelte/reactivity';
import { SvelteMap } from 'svelte/reactivity';

let state = new Map([[0, 0]]);
let state = new SvelteMap([[0, 0]]);
</script>

<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { Set } from 'svelte/reactivity';
import { SvelteSet } from 'svelte/reactivity';

let state = new Set([0]);
let state = new SvelteSet([0]);
</script>

<button onclick={() => state.delete(0)}>delete initial</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script>
import { Set as ReactiveSet, Map as ReactiveMap } from 'svelte/reactivity';
import { SvelteSet, SvelteMap } from 'svelte/reactivity';

let map = new Map();
let set = new Set();
let rmap = new ReactiveMap();
let rset = new ReactiveSet();
let rmap = new SvelteMap();
let rset = new SvelteSet();
</script>

<div>{rset.entries()} {rset.keys()} {rset.values()}</div>
<div>{set.entries()} {set.keys()} {set.values()}</div>
<div>{rmap.entries()} {rmap.keys()} {rmap.values()}</div>
<div>{map.entries()} {map.keys()} {map.values()}</div>
<div>{map.entries()} {map.keys()} {map.values()}</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { URL } from 'svelte/reactivity';
import { SvelteURL } from 'svelte/reactivity';

let url = new URL('https://svelte.dev/repl/hello-world?version=5.0');
let url = new SvelteURL('https://svelte.dev/repl/hello-world?version=5.0');
</script>

<div>href: {url.href}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { Set } from 'svelte/reactivity';
const set = new Set();
import { SvelteSet } from 'svelte/reactivity';
const set = new SvelteSet();
</script>

<form onsubmit={e => {
Expand Down
Loading