-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathServiceWorker.elm
113 lines (68 loc) · 1.83 KB
/
ServiceWorker.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
port module ServiceWorker exposing
( Availability(..)
, Error
, Registration(..)
, checkAvailability
, getAvailability
, getRegistration
, onMessage
, onSync
, postMessage
, register
, sendBroadcast
, subscribePush
)
import Json.Decode as JD
import Json.Encode as JE
type Availability
= Unknown
| Available
| NotAvailable
type Registration
= RegistrationUnknown
| RegistrationSuccess
| RegistrationError
type alias Error =
String
register : Cmd msg
register =
registrationRequest ()
subscribePush : String -> Cmd msg
subscribePush s =
subscribeInternal s
postMessage : JE.Value -> Cmd msg
postMessage =
postMessageInternal
getRegistration : (Registration -> msg) -> Sub msg
getRegistration f =
registrationResponse (registrationFromString >> f)
registrationFromString : String -> Registration
registrationFromString s =
if s == "success" then
RegistrationSuccess
else
RegistrationError
port availabilityResponse : (Bool -> msg) -> Sub msg
port availabilityRequest : () -> Cmd msg
port postMessageInternal : JE.Value -> Cmd msg
port onMessageInternal : (JD.Value -> msg) -> Sub msg
port registrationRequest : () -> Cmd msg
port registrationResponse : (String -> msg) -> Sub msg
port subscribeInternal : String -> Cmd msg
port sendBroadcast : Bool -> Cmd msg
port onSync : (String -> msg) -> Sub msg
checkAvailability : Cmd msg
checkAvailability =
availabilityRequest ()
getAvailability : (Availability -> msg) -> Sub msg
getAvailability msg =
availabilityResponse (availabilityFromBool >> msg)
onMessage : (JD.Value -> msg) -> Sub msg
onMessage =
onMessageInternal
availabilityFromBool : Bool -> Availability
availabilityFromBool b =
if b then
Available
else
NotAvailable