Skip to content

Commit cae5f1e

Browse files
trueadmConduitry
andauthored
breaking: rename svelte/reactivity helpers to include Svelte prefix (#12248)
* breaking: rename svelte/reactivity helpers to include Svelte prefix * keep old exports * add runtime errors * add runtime errors * feedback * feedback * feedback * Update .changeset/nice-jobs-breathe.md Co-authored-by: Conduitry <[email protected]> --------- Co-authored-by: Conduitry <[email protected]>
1 parent 9a293ea commit cae5f1e

File tree

18 files changed

+127
-62
lines changed

18 files changed

+127
-62
lines changed

.changeset/nice-jobs-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
breaking: rename `svelte/reactivity` helpers to include `Svelte` prefix

packages/svelte/src/reactivity/date.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ const write = [
5757

5858
var inited = false;
5959

60-
export class ReactiveDate extends Date {
60+
export class SvelteDate extends Date {
6161
#raw_time = source(super.getTime());
6262

6363
// We init as part of the first instance so that we can treeshake this class
6464
#init() {
6565
if (!inited) {
6666
inited = true;
67-
const proto = ReactiveDate.prototype;
67+
const proto = SvelteDate.prototype;
6868
const date_proto = Date.prototype;
6969

7070
for (const method of read) {
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
export { ReactiveDate as Date } from './date.js';
2-
export { ReactiveSet as Set } from './set.js';
3-
export { ReactiveMap as Map } from './map.js';
4-
export { ReactiveURL as URL, ReactiveURLSearchParams as URLSearchParams } from './url.js';
1+
export { SvelteDate } from './date.js';
2+
export { SvelteSet } from './set.js';
3+
export { SvelteMap } from './map.js';
4+
export { SvelteURL, SvelteURLSearchParams } from './url.js';
5+
6+
/** @deprecated Use `SvelteDate` instead */
7+
export function Date() {
8+
throw new Error('Date has been removed, use SvelteDate instead.');
9+
}
10+
11+
/** @deprecated Use `SvelteSet` instead */
12+
export function Set() {
13+
throw new Error('Set has been removed, use SvelteSet instead.');
14+
}
15+
16+
/** @deprecated Use `SvelteMap` instead */
17+
export function Map() {
18+
throw new Error('Map has been removed, use SvelteMap instead.');
19+
}
20+
21+
/** @deprecated Use `SvelteURL` instead */
22+
export function URL() {
23+
throw new Error('URL has been removed, use SvelteURL instead.');
24+
}
25+
26+
/** @deprecated Use `SvelteURLSearchParams` instead */
27+
export function URLSearchParams() {
28+
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
29+
}
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
export const Date = globalThis.Date;
2-
export const Set = globalThis.Set;
3-
export const Map = globalThis.Map;
4-
export const URL = globalThis.URL;
5-
export const URLSearchParams = globalThis.URLSearchParams;
1+
export const SvelteDate = globalThis.Date;
2+
export const SvelteSet = globalThis.Set;
3+
export const SvelteMap = globalThis.Map;
4+
export const SvelteURL = globalThis.URL;
5+
export const SvelteURLSearchParams = globalThis.URLSearchParams;
6+
7+
/** @deprecated Use `SvelteDate` instead */
8+
export function Date() {
9+
throw new Error('Date has been removed, use SvelteDate instead.');
10+
}
11+
12+
/** @deprecated Use `SvelteSet` instead */
13+
export function Set() {
14+
throw new Error('Set has been removed, use SvelteSet instead.');
15+
}
16+
17+
/** @deprecated Use `SvelteMap` instead */
18+
export function Map() {
19+
throw new Error('Map has been removed, use SvelteMap instead.');
20+
}
21+
22+
/** @deprecated Use `SvelteURL` instead */
23+
export function URL() {
24+
throw new Error('URL has been removed, use SvelteURL instead.');
25+
}
26+
27+
/** @deprecated Use `SvelteURLSearchParams` instead */
28+
export function URLSearchParams() {
29+
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
30+
}

packages/svelte/src/reactivity/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { increment } from './utils.js';
88
* @template V
99
* @extends {Map<K, V>}
1010
*/
11-
export class ReactiveMap extends Map {
11+
export class SvelteMap extends Map {
1212
/** @type {Map<K, import('#client').Source<number>>} */
1313
#sources = new Map();
1414
#version = source(0);

packages/svelte/src/reactivity/map.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
22
import { flushSync } from '../index-client.js';
3-
import { ReactiveMap } from './map.js';
3+
import { SvelteMap } from './map.js';
44
import { assert, test } from 'vitest';
55

66
test('map.values()', () => {
7-
const map = new ReactiveMap([
7+
const map = new SvelteMap([
88
[1, 1],
99
[2, 2],
1010
[3, 3],
@@ -65,7 +65,7 @@ test('map.values()', () => {
6565
});
6666

6767
test('map.get(...)', () => {
68-
const map = new ReactiveMap([
68+
const map = new SvelteMap([
6969
[1, 1],
7070
[2, 2],
7171
[3, 3]
@@ -101,7 +101,7 @@ test('map.get(...)', () => {
101101
});
102102

103103
test('map.has(...)', () => {
104-
const map = new ReactiveMap([
104+
const map = new SvelteMap([
105105
[1, 1],
106106
[2, 2],
107107
[3, 3]
@@ -148,7 +148,7 @@ test('map.has(...)', () => {
148148
});
149149

150150
test('map.forEach(...)', () => {
151-
const map = new ReactiveMap([
151+
const map = new SvelteMap([
152152
[1, 1],
153153
[2, 2],
154154
[3, 3]
@@ -169,7 +169,7 @@ test('map.forEach(...)', () => {
169169
});
170170

171171
test('map.delete(...)', () => {
172-
const map = new ReactiveMap([
172+
const map = new SvelteMap([
173173
[1, 1],
174174
[2, 2],
175175
[3, 3]
@@ -182,7 +182,7 @@ test('map.delete(...)', () => {
182182
});
183183

184184
test('map handling of undefined values', () => {
185-
const map = new ReactiveMap();
185+
const map = new SvelteMap();
186186

187187
const log: any = [];
188188

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

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

213213
const log: any = [];
214214

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

238238
test('Map.instanceOf', () => {
239-
assert.equal(new ReactiveMap() instanceof Map, true);
239+
assert.equal(new SvelteMap() instanceof Map, true);
240240
});

packages/svelte/src/reactivity/set.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var inited = false;
1212
* @template T
1313
* @extends {Set<T>}
1414
*/
15-
export class ReactiveSet extends Set {
15+
export class SvelteSet extends Set {
1616
/** @type {Map<T, import('#client').Source<boolean>>} */
1717
#sources = new Map();
1818
#version = source(0);
@@ -41,7 +41,7 @@ export class ReactiveSet extends Set {
4141
#init() {
4242
inited = true;
4343

44-
var proto = ReactiveSet.prototype;
44+
var proto = SvelteSet.prototype;
4545
var set_proto = Set.prototype;
4646

4747
for (const method of read_methods) {
@@ -59,7 +59,7 @@ export class ReactiveSet extends Set {
5959
get(this.#version);
6060
// @ts-ignore
6161
var set = /** @type {Set<T>} */ (set_proto[method].apply(this, v));
62-
return new ReactiveSet(set);
62+
return new SvelteSet(set);
6363
};
6464
}
6565
}

packages/svelte/src/reactivity/set.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
22
import { flushSync } from '../index-client.js';
3-
import { ReactiveSet } from './set.js';
3+
import { SvelteSet } from './set.js';
44
import { assert, test } from 'vitest';
55

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

99
const log: any = [];
1010

@@ -36,7 +36,7 @@ test('set.values()', () => {
3636
});
3737

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

4141
const log: any = [];
4242

@@ -79,7 +79,7 @@ test('set.has(...)', () => {
7979
});
8080

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

8484
assert.equal(set.delete(3), true);
8585
assert.equal(set.delete(3), false);
@@ -88,7 +88,7 @@ test('set.delete(...)', () => {
8888
});
8989

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

9393
const log: any = [];
9494

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

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

113113
const log: any = [];
114114

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

157157
test('Set.instanceOf', () => {
158-
assert.equal(new ReactiveSet() instanceof Set, true);
158+
assert.equal(new SvelteSet() instanceof Set, true);
159159
});

packages/svelte/src/reactivity/url.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { increment } from './utils.js';
44

55
const REPLACE = Symbol();
66

7-
export class ReactiveURL extends URL {
7+
export class SvelteURL extends URL {
88
#protocol = source(super.protocol);
99
#username = source(super.username);
1010
#password = source(super.password);
1111
#hostname = source(super.hostname);
1212
#port = source(super.port);
1313
#pathname = source(super.pathname);
1414
#hash = source(super.hash);
15-
#searchParams = new ReactiveURLSearchParams();
15+
#searchParams = new SvelteURLSearchParams();
1616

1717
/**
1818
* @param {string | URL} url
@@ -153,7 +153,7 @@ export class ReactiveURL extends URL {
153153
}
154154
}
155155

156-
export class ReactiveURLSearchParams extends URLSearchParams {
156+
export class SvelteURLSearchParams extends URLSearchParams {
157157
#version = source(0);
158158

159159
/**

packages/svelte/src/reactivity/url.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { render_effect, effect_root } from '../internal/client/reactivity/effects.js';
22
import { flushSync } from '../index-client.js';
3-
import { ReactiveURL, ReactiveURLSearchParams } from './url.js';
3+
import { SvelteURL, SvelteURLSearchParams } from './url.js';
44
import { assert, test } from 'vitest';
55

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

1010
const cleanup = effect_root(() => {
@@ -32,7 +32,7 @@ test('url.hash', () => {
3232
});
3333

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

3838
const cleanup = effect_root(() => {
@@ -78,7 +78,7 @@ test('url.searchParams', () => {
7878
});
7979

8080
test('URLSearchParams', () => {
81-
const params = new ReactiveURLSearchParams();
81+
const params = new SvelteURLSearchParams();
8282
const log: any = [];
8383

8484
const cleanup = effect_root(() => {

0 commit comments

Comments
 (0)