Skip to content

Commit 6a6e2af

Browse files
committed
docs: add inline documentation for svelte/reactivity
1 parent 475b5db commit 6a6e2af

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

packages/svelte/src/reactivity/date.js

+32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ import { active_reaction, get, set_active_reaction } from '../internal/client/ru
55

66
var inited = false;
77

8+
/**
9+
* A reactive version of the built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object.
10+
* Reading the date in an [effect](https://svelte.dev/docs/svelte/$effect) or [derived](https://svelte.dev/docs/svelte/$derived) (whether with methods like `date.getTime()` or `date.toString()`,
11+
* or via things like [`Intl.DateTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat)) will cause it to be re-evaluated when the
12+
* value of the date changes.
13+
*
14+
* ```svelte
15+
* <script>
16+
* import { SvelteDate } from 'svelte/reactivity';
17+
*
18+
* const date = new SvelteDate();
19+
*
20+
* const formatter = new Intl.DateTimeFormat(undefined, {
21+
* hour: 'numeric',
22+
* minute: 'numeric',
23+
* second: 'numeric'
24+
* });
25+
*
26+
* $effect(() => {
27+
* const interval = setInterval(() => {
28+
* date.setTime(Date.now());
29+
* }, 1000);
30+
*
31+
* return () => {
32+
* clearInterval(interval);
33+
* };
34+
* });
35+
* </script>
36+
*
37+
* <p>The time is {formatter.format(date)}</p>
38+
* ```
39+
*/
840
export class SvelteDate extends Date {
941
#time = source(super.getTime());
1042

packages/svelte/types/index.d.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,38 @@ declare module 'svelte/motion' {
18981898
}
18991899

19001900
declare module 'svelte/reactivity' {
1901+
/**
1902+
* A reactive version of the built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object.
1903+
* Reading the date in an [effect](https://svelte.dev/docs/svelte/$effect) or [derived](https://svelte.dev/docs/svelte/$derived) (whether with methods like `date.getTime()` or `date.toString()`,
1904+
* or via things like [`Intl.DateTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat)) will cause it to be re-evaluated when the
1905+
* value of the date changes.
1906+
*
1907+
* ```svelte
1908+
* <script>
1909+
* import { SvelteDate } from 'svelte/reactivity';
1910+
*
1911+
* const date = new SvelteDate();
1912+
*
1913+
* const formatter = new Intl.DateTimeFormat(undefined, {
1914+
* hour: 'numeric',
1915+
* minute: 'numeric',
1916+
* second: 'numeric'
1917+
* });
1918+
*
1919+
* $effect(() => {
1920+
* const interval = setInterval(() => {
1921+
* date.setTime(Date.now());
1922+
* }, 1000);
1923+
*
1924+
* return () => {
1925+
* clearInterval(interval);
1926+
* };
1927+
* });
1928+
* </script>
1929+
*
1930+
* <p>The time is {formatter.format(date)}</p>
1931+
* ```
1932+
*/
19011933
export class SvelteDate extends Date {
19021934

19031935
constructor(...params: any[]);

0 commit comments

Comments
 (0)