~toastal/purescript-web-network-information

21dd46ea504f1d8923d40a4d0ddb9f73fa154bec — toastal 3 years ago ff88925 v0.3.0
fromEventTarget
2 files changed, 11 insertions(+), 9 deletions(-)

M flake.lock
M src/Web/NetworkInformation.purs
M flake.lock => flake.lock +3 -3
@@ 33,11 33,11 @@
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1633971123,
        "narHash": "sha256-WmI4NbH1IPGFWVkuBkKoYgOnxgwSfWDgdZplJlQ93vA=",
        "lastModified": 1634172192,
        "narHash": "sha256-FBF4U/T+bMg4sEyT/zkgasvVquGzgdAf4y8uCosKMmo=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "e4ef597edfd8a0ba5f12362932fc9b1dd01a0aef",
        "rev": "2cf9db0e3d45b9d00f16f2836cb1297bcadc475e",
        "type": "github"
      },
      "original": {

M src/Web/NetworkInformation.purs => src/Web/NetworkInformation.purs +8 -6
@@ 12,6 12,7 @@ module Web.NetworkInformation
   , saveData
   , onChange
   , toEventTarget
   , fromEventTarget
   , module Exports
   ) where



@@ 26,6 27,7 @@ import Safe.Coerce (coerce)
import Unsafe.Coerce (unsafeCoerce)
import Web.Event.Event (Event)
import Web.Event.EventTarget (EventTarget)
import Web.Internal.FFI (unsafeReadProtoTagged)
import Web.NetworkInformation.ConnectionType (ConnectionType(..)) as Exports
import Web.NetworkInformation.ConnectionType (ConnectionType)
import Web.NetworkInformation.ConnectionType as ConnectionType


@@ 39,6 41,12 @@ import Web.NetworkInformation.Megabit (Megabit)
-- | about the network connection the user agent is currently using
foreign import data NetworkInformation ∷ Type

toEventTarget ∷ NetworkInformation → EventTarget
toEventTarget = unsafeCoerce

fromEventTarget ∷ EventTarget → Maybe NetworkInformation
fromEventTarget = unsafeReadProtoTagged "NetworkInformation"

foreign import getProp ∷ ∀ a. EffectFn2 String NetworkInformation (Nullable a)

-- | The type attribute, when getting, returns the connection type that the


@@ 99,9 107,3 @@ foreign import onChangeImpl ∷ ∀ a. EffectFn2 (Event → Effect a) NetworkInf
-- | during the steps to update the connection values.
onChange ∷ ∀ a. (Event → Effect a) → NetworkInformation → Effect Unit
onChange = runEffectFn2 onChangeImpl

-- | `NetworkInformation` has access to an `onchange` event which can be
-- | consumed with `Web.Event.EventTarget.addEventListener`, etc.
toEventTarget ∷ NetworkInformation → EventTarget
toEventTarget = unsafeCoerce