Skip to content

Commit

Permalink
tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 11, 2024
1 parent cb2efe6 commit 42b8d77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: svelte/reactivity/window
---

This module exports reactive versions of various `window` properties, which you can use in components and [deriveds]($derived) and [effects]($effect) without using [`<svelte:window>`](svelte-window) bindings or manually creating your own event listeners.
This module exports reactive versions of various `window` values, each of which has a reactive `current` property that you can reference in reactive contexts (templates, [deriveds]($derived) and [effects]($effect)) without using [`<svelte:window>`](svelte-window) bindings or manually creating your own event listeners.

```svelte
<script>
Expand Down
20 changes: 10 additions & 10 deletions packages/svelte/src/reactivity/window/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,55 @@ import { get } from '../../internal/client/index.js';
import { set, source } from '../../internal/client/reactivity/sources.js';

/**
* `scrollX.current` is a reactive view of `window.scrollX`. On the server it is `undefined`
* `scrollX.current` is a reactive view of `window.scrollX`. On the server it is `undefined`.
*/
export const scrollX = new ReactiveValue(
BROWSER ? () => window.scrollX : () => undefined,
(update) => on(window, 'scroll', update)
);

/**
* `scrollY.current` is a reactive view of `window.scrollY`. On the server it is `undefined`
* `scrollY.current` is a reactive view of `window.scrollY`. On the server it is `undefined`.
*/
export const scrollY = new ReactiveValue(
BROWSER ? () => window.scrollY : () => undefined,
(update) => on(window, 'scroll', update)
);

/**
* `innerWidth.current` is a reactive view of `window.innerWidth`. On the server it is `undefined`
* `innerWidth.current` is a reactive view of `window.innerWidth`. On the server it is `undefined`.
*/
export const innerWidth = new ReactiveValue(
BROWSER ? () => window.innerWidth : () => undefined,
(update) => on(window, 'resize', update)
);

/**
* `innerHeight.current` is a reactive view of `window.innerHeight`. On the server it is `undefined`
* `innerHeight.current` is a reactive view of `window.innerHeight`. On the server it is `undefined`.
*/
export const innerHeight = new ReactiveValue(
BROWSER ? () => window.innerHeight : () => undefined,
(update) => on(window, 'resize', update)
);

/**
* `outerWidth.current` is a reactive view of `window.outerWidth`. On the server it is `undefined`
* `outerWidth.current` is a reactive view of `window.outerWidth`. On the server it is `undefined`.
*/
export const outerWidth = new ReactiveValue(
BROWSER ? () => window.outerWidth : () => undefined,
(update) => on(window, 'resize', update)
);

/**
* `outerHeight.current` is a reactive view of `window.outerHeight`. On the server it is `undefined`
* `outerHeight.current` is a reactive view of `window.outerHeight`. On the server it is `undefined`.
*/
export const outerHeight = new ReactiveValue(
BROWSER ? () => window.outerHeight : () => undefined,
(update) => on(window, 'resize', update)
);

/**
* `screenLeft.current` is a reactive view of `window.screenLeft`. On the server it is `undefined`
* `screenLeft.current` is a reactive view of `window.screenLeft`. On the server it is `undefined`.
*/
export const screenLeft = new ReactiveValue(
BROWSER ? () => window.screenLeft : () => undefined,
Expand All @@ -75,7 +75,7 @@ export const screenLeft = new ReactiveValue(
);

/**
* `screenTop.current` is a reactive view of `window.screenTop`. On the server it is `undefined`
* `screenTop.current` is a reactive view of `window.screenTop`. On the server it is `undefined`.
*/
export const screenTop = new ReactiveValue(
BROWSER ? () => window.screenTop : () => undefined,
Expand All @@ -97,7 +97,7 @@ export const screenTop = new ReactiveValue(
);

/**
* `online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`
* `online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`.
*/
export const online = new ReactiveValue(
BROWSER ? () => navigator.onLine : () => undefined,
Expand All @@ -114,7 +114,7 @@ export const online = new ReactiveValue(
/**
* `devicePixelRatio.current` is a reactive view of `window.devicePixelRatio`. On the server it is `undefined`.
* Note that behaviour differs between browsers — on Chrome it will respond to the current zoom level,
* on Firefox and Safari it won't
* on Firefox and Safari it won't.
* @type {{ get current(): number }}
*/
export const devicePixelRatio = /* @__PURE__ */ new (class DevicePixelRatio {
Expand Down
20 changes: 10 additions & 10 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,45 +1964,45 @@ declare module 'svelte/reactivity' {

declare module 'svelte/reactivity/window' {
/**
* `scrollX.current` is a reactive view of `window.scrollX`. On the server it is `undefined`
* `scrollX.current` is a reactive view of `window.scrollX`. On the server it is `undefined`.
*/
export const scrollX: ReactiveValue<number | undefined>;
/**
* `scrollY.current` is a reactive view of `window.scrollY`. On the server it is `undefined`
* `scrollY.current` is a reactive view of `window.scrollY`. On the server it is `undefined`.
*/
export const scrollY: ReactiveValue<number | undefined>;
/**
* `innerWidth.current` is a reactive view of `window.innerWidth`. On the server it is `undefined`
* `innerWidth.current` is a reactive view of `window.innerWidth`. On the server it is `undefined`.
*/
export const innerWidth: ReactiveValue<number | undefined>;
/**
* `innerHeight.current` is a reactive view of `window.innerHeight`. On the server it is `undefined`
* `innerHeight.current` is a reactive view of `window.innerHeight`. On the server it is `undefined`.
*/
export const innerHeight: ReactiveValue<number | undefined>;
/**
* `outerWidth.current` is a reactive view of `window.outerWidth`. On the server it is `undefined`
* `outerWidth.current` is a reactive view of `window.outerWidth`. On the server it is `undefined`.
*/
export const outerWidth: ReactiveValue<number | undefined>;
/**
* `outerHeight.current` is a reactive view of `window.outerHeight`. On the server it is `undefined`
* `outerHeight.current` is a reactive view of `window.outerHeight`. On the server it is `undefined`.
*/
export const outerHeight: ReactiveValue<number | undefined>;
/**
* `screenLeft.current` is a reactive view of `window.screenLeft`. On the server it is `undefined`
* `screenLeft.current` is a reactive view of `window.screenLeft`. On the server it is `undefined`.
*/
export const screenLeft: ReactiveValue<number | undefined>;
/**
* `screenTop.current` is a reactive view of `window.screenTop`. On the server it is `undefined`
* `screenTop.current` is a reactive view of `window.screenTop`. On the server it is `undefined`.
*/
export const screenTop: ReactiveValue<number | undefined>;
/**
* `online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`
* `online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`.
*/
export const online: ReactiveValue<boolean | undefined>;
/**
* `devicePixelRatio.current` is a reactive view of `window.devicePixelRatio`. On the server it is `undefined`.
* Note that behaviour differs between browsers — on Chrome it will respond to the current zoom level,
* on Firefox and Safari it won't
* on Firefox and Safari it won't.
* */
export const devicePixelRatio: {
get current(): number;
Expand Down

0 comments on commit 42b8d77

Please sign in to comment.