Skip to content

Commit

Permalink
online binding
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Dec 10, 2024
1 parent c87d27a commit cb2efe6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/svelte/src/reactivity/window/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ export const screenTop = new ReactiveValue(
}
);

/**
* `online.current` is a reactive view of `navigator.onLine`. On the server it is `undefined`
*/
export const online = new ReactiveValue(
BROWSER ? () => navigator.onLine : () => undefined,
(update) => {
const unsub_online = on(window, 'online', update);
const unsub_offline = on(window, 'offline', update);
return () => {
unsub_online();
unsub_offline();
};
}
);

/**
* `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,
Expand Down
4 changes: 4 additions & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,10 @@ declare module 'svelte/reactivity/window' {
* `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`
*/
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,
Expand Down

0 comments on commit cb2efe6

Please sign in to comment.