@@ -1,7 +1,4 @@
1−module Generate.JavaScript.Port
1+module Generate.JavaScript.Port (inbound, outbound, task) where
2− ( inbound, inboundSignal
3− , outbound, outboundSignal
6import qualified Data.List as List
3import qualified Data.List as List
7import Language.ECMAScript3.Syntax
4import Language.ECMAScript3.Syntax
@@ -12,6 +9,21 @@ import qualified AST.Variable as Var
12import Generate.JavaScript.Helpers
9import Generate.JavaScript.Helpers
14+task :: String -> Expression () -> T.PortType var -> Expression ()
15+task name expr portType =
18+ _Task "perform" `call` [ expr ]
21+ _Task "performSignal" `call` [ string name, expr ]
15data JSType
27data JSType
16 = JSNumber
28 = JSNumber
17 | JSBoolean
29 | JSBoolean
@@ -51,6 +63,11 @@ _Port functionName =
51 useLazy ["Elm","Native","Port"] functionName
63 useLazy ["Elm","Native","Port"] functionName
66+_Task :: String -> Expression ()
68+ useLazy ["Elm","Native","Task"] functionName
54check :: Expression () -> JSType -> Expression () -> Expression ()
71check :: Expression () -> JSType -> Expression () -> Expression ()
55check x jsType continue =
72check x jsType continue =
56 CondExpr () (jsFold OpLOr checks x) continue throw
73 CondExpr () (jsFold OpLOr checks x) continue throw
@@ -73,22 +90,22 @@ check x jsType continue =
76−inbound :: String -> CanonicalType -> Expression ()
93+inbound :: String -> T.PortType Var.Canonical -> Expression ()
77−inbound name tipe =
94+inbound name portType =
78− _Port "inbound" `call`
97+ _Port "inbound" `call`
79− [ string name
98+ [ string name
80− , string (show (pretty tipe))
99+ , string (show (pretty tipe))
81− , toTypeFunction tipe
100+ , toTypeFunction tipe
84−
103+ T.Signal _root arg ->
85−inboundSignal :: String -> CanonicalType -> Expression ()
86−inboundSignal name tipe =
87− _Port "inboundSignal" `call`
104+ _Port "inboundSignal" `call`
88− [ string name
105+ [ string name
89− , string (show (pretty tipe))
106+ , string (show (pretty arg))
90− , toTypeFunction tipe
107+ , toTypeFunction arg
94toTypeFunction :: CanonicalType -> Expression ()
111toTypeFunction :: CanonicalType -> Expression ()
@@ -178,14 +195,14 @@ toTuple types x =
179-- OUTBOUND
196-- OUTBOUND
181−outbound :: String -> CanonicalType -> Expression () -> Expression ()
198+outbound :: String -> Expression () -> T.PortType Var.Canonical -> Expression ()
182−outbound name tipe expr =
199+outbound name expr portType =
183− _Port "outbound" `call` [ string name, fromTypeFunction tipe, expr ]
202+ _Port "outbound" `call` [ string name, fromTypeFunction tipe, expr ]
186−outboundSignal :: String -> CanonicalType -> Expression () -> Expression ()
204+ T.Signal _ arg ->
187−outboundSignal name tipe expr =
188− _Port "outboundSignal" `call` [ string name, fromTypeFunction tipe, expr ]
205+ _Port "outboundSignal" `call` [ string name, fromTypeFunction arg, expr ]
191fromTypeFunction :: CanonicalType -> Expression ()
208fromTypeFunction :: CanonicalType -> Expression ()