You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Svelte store for the (experimental) Network Information API
1
+
# Svelte Network Information API
2
+
3
+
This library provides a readable Svelte store to use a PWA's access to the [`Network Information API`](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation), available on the navigator. It allows you to subscribe to network changes and read the provided values.
4
+
5
+
> Note:
6
+
> 'Network Information API' is currently experimental and only supported in a very limited set of browsers.
7
+
8
+
## Install
9
+
10
+
```text
11
+
npm i -D svelte-network-information
12
+
```
13
+
14
+
## Usage
15
+
16
+
### Basic
17
+
18
+
This library provides a simple readable store that automatically subscribes to events of a connection instance of `NetworkInformation`, an API of the `navigator` to access detailed metrics regarding network states.
19
+
20
+
```svelte
21
+
<script lang="ts">
22
+
import { networkInformationStore as store } from 'svelte-network-information';
23
+
</script>
24
+
25
+
<ul>
26
+
<li>State: {$store.state}</li>
27
+
<li>connectivity: {$store.connectivity}</li>
28
+
<li>downlink: {$store.downlink}</li>
29
+
<li>downlinkMax: {$store.downlinkMax}</li>
30
+
<li>effectiveType: {$store.effectiveType}</li>
31
+
<li>rtt: {$store.rtt}</li>
32
+
<li>saveData: {$store.saveData}</li>
33
+
<li>type: {$store.type}</li>
34
+
</ul>
35
+
```
36
+
37
+
### Derived
38
+
39
+
To subscribe to changes for only a specific selection of values, simply create a `derived` store.
40
+
41
+
```svelte
42
+
<script lang="ts">
43
+
import { networkInformationStore } from 'svelte-network-information';
Svelte store for the (experimental) Network Information API
1
+
# Svelte Network Information API
2
+
3
+
This library provides a readable Svelte store to use a PWA's access to the [`Network Information API`](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation), available on the navigator. It allows you to subscribe to network changes and read the provided values.
4
+
5
+
> Note:
6
+
> 'Network Information API' is currently experimental and only supported in a very limited set of browsers.
7
+
8
+
## Install
9
+
10
+
```text
11
+
npm i -D svelte-network-information
12
+
```
13
+
14
+
## Usage
15
+
16
+
### Basic
17
+
18
+
This library provides a simple readable store that automatically subscribes to events of a connection instance of `NetworkInformation`, an API of the `navigator` to access detailed metrics regarding network states.
19
+
20
+
```svelte
21
+
<script lang="ts">
22
+
import { networkInformationStore as store } from 'svelte-network-information';
23
+
</script>
24
+
25
+
<ul>
26
+
<li>State: {$store.state}</li>
27
+
<li>connectivity: {$store.connectivity}</li>
28
+
<li>downlink: {$store.downlink}</li>
29
+
<li>downlinkMax: {$store.downlinkMax}</li>
30
+
<li>effectiveType: {$store.effectiveType}</li>
31
+
<li>rtt: {$store.rtt}</li>
32
+
<li>saveData: {$store.saveData}</li>
33
+
<li>type: {$store.type}</li>
34
+
</ul>
35
+
```
36
+
37
+
### Derived
38
+
39
+
To subscribe to changes for only a specific selection of values, simply create a `derived` store.
40
+
41
+
```svelte
42
+
<script lang="ts">
43
+
import { networkInformationStore } from 'svelte-network-information';
0 commit comments