Skip to content

Commit 991793a

Browse files
authored
fix(useNetwork): return immutable values (#4187)
1 parent 044dd7a commit 991793a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

packages/core/useNetwork/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* this implementation is original ported from https://github.com/logaretm/vue-use-web by Abdelrahman Awad */
22

33
import type { Ref } from 'vue-demi'
4-
import { ref } from 'vue-demi'
4+
import { readonly, ref } from 'vue-demi'
55
import { useEventListener } from '../useEventListener'
66
import { useSupported } from '../useSupported'
77
import type { ConfigurableWindow } from '../_configurable'
@@ -12,43 +12,43 @@ export type NetworkType = 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi
1212
export type NetworkEffectiveType = 'slow-2g' | '2g' | '3g' | '4g' | undefined
1313

1414
export interface NetworkState {
15-
isSupported: Ref<boolean>
15+
isSupported: Readonly<Ref<boolean>>
1616
/**
1717
* If the user is currently connected.
1818
*/
19-
isOnline: Ref<boolean>
19+
isOnline: Readonly<Ref<boolean>>
2020
/**
2121
* The time since the user was last connected.
2222
*/
23-
offlineAt: Ref<number | undefined>
23+
offlineAt: Readonly<Ref<number | undefined>>
2424
/**
2525
* At this time, if the user is offline and reconnects
2626
*/
27-
onlineAt: Ref<number | undefined>
27+
onlineAt: Readonly<Ref<number | undefined>>
2828
/**
2929
* The download speed in Mbps.
3030
*/
31-
downlink: Ref<number | undefined>
31+
downlink: Readonly<Ref<number | undefined>>
3232
/**
3333
* The max reachable download speed in Mbps.
3434
*/
35-
downlinkMax: Ref<number | undefined>
35+
downlinkMax: Readonly<Ref<number | undefined>>
3636
/**
3737
* The detected effective speed type.
3838
*/
39-
effectiveType: Ref<NetworkEffectiveType | undefined>
39+
effectiveType: Readonly<Ref<NetworkEffectiveType | undefined>>
4040
/**
4141
* The estimated effective round-trip time of the current connection.
4242
*/
43-
rtt: Ref<number | undefined>
43+
rtt: Readonly<Ref<number | undefined>>
4444
/**
4545
* If the user activated data saver mode.
4646
*/
47-
saveData: Ref<boolean | undefined>
47+
saveData: Readonly<Ref<boolean | undefined>>
4848
/**
4949
* The detected connection/network type.
5050
*/
51-
type: Ref<NetworkType>
51+
type: Readonly<Ref<NetworkType>>
5252
}
5353

5454
/**
@@ -110,16 +110,16 @@ export function useNetwork(options: ConfigurableWindow = {}): Readonly<NetworkSt
110110
updateNetworkInformation()
111111

112112
return {
113-
isSupported,
114-
isOnline,
115-
saveData,
116-
offlineAt,
117-
onlineAt,
118-
downlink,
119-
downlinkMax,
120-
effectiveType,
121-
rtt,
122-
type,
113+
isSupported: readonly(isSupported),
114+
isOnline: readonly(isOnline),
115+
saveData: readonly(saveData),
116+
offlineAt: readonly(offlineAt),
117+
onlineAt: readonly(onlineAt),
118+
downlink: readonly(downlink),
119+
downlinkMax: readonly(downlinkMax),
120+
effectiveType: readonly(effectiveType),
121+
rtt: readonly(rtt),
122+
type: readonly(type),
123123
}
124124
}
125125

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy