Skip to content

Commit

Permalink
Remove Void and use () instead
Browse files Browse the repository at this point in the history
  • Loading branch information
arowM committed Jul 8, 2023
1 parent 7b9fd77 commit 716edf9
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 171 deletions.
12 changes: 6 additions & 6 deletions spa-sample/src/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Json.Encode exposing (Value)
import Mixin.Html as Html exposing (Html)
import Page.Home as PageHome
import Page.Login as PageLogin
import Tepa exposing (Document, Layer, Msg, NavKey, Promise, Void)
import Tepa exposing (Document, Layer, Msg, NavKey, Promise)
import Tepa.Http as Http
import Tepa.Navigation as Nav
import Tepa.Random as Random
Expand Down Expand Up @@ -135,12 +135,12 @@ pageNotFoundView =


{-| -}
procedure : Value -> AppUrl -> NavKey -> Promise Memory Void
procedure : Value -> AppUrl -> NavKey -> Promise Memory ()
procedure _ url key =
pageProcedure url key Nothing


onUrlChange : flags -> AppUrl -> NavKey -> Promise Memory Void
onUrlChange : flags -> AppUrl -> NavKey -> Promise Memory ()
onUrlChange _ newUrl key =
Tepa.bind Tepa.currentState <|
\state ->
Expand All @@ -166,7 +166,7 @@ onUrlChange _ newUrl key =
]


onUrlRequest : flags -> Tepa.UrlRequest -> NavKey -> Promise Memory Void
onUrlRequest : flags -> Tepa.UrlRequest -> NavKey -> Promise Memory ()
onUrlRequest _ urlRequest key =
case urlRequest of
Tepa.InternalPath url ->
Expand All @@ -184,10 +184,10 @@ pageProcedure :
AppUrl
-> NavKey
-> Maybe Session
-> Promise Memory Void
-> Promise Memory ()
pageProcedure url key msession =
let
withSession : (Session -> Promise Memory Void) -> Promise Memory Void
withSession : (Session -> Promise Memory ()) -> Promise Memory ()
withSession action =
case msession of
Just session ->
Expand Down
10 changes: 5 additions & 5 deletions spa-sample/src/Page/Home.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Json.Encode exposing (Value)
import Mixin exposing (Mixin)
import Mixin.Html as Html exposing (Html)
import Page.Home.EditAccount as EditAccount
import Tepa exposing (Layer, Msg, NavKey, Promise, ViewContext, Void)
import Tepa exposing (Layer, Msg, NavKey, Promise, ViewContext)
import Tepa.Http as Http
import Tepa.Navigation as Nav
import Tepa.Scenario as Scenario exposing (Scenario)
Expand Down Expand Up @@ -335,7 +335,7 @@ type alias Bucket =


{-| -}
procedure : NavKey -> AppUrl -> Promise Memory Void
procedure : NavKey -> AppUrl -> Promise Memory ()
procedure key url =
let
bucket =
Expand All @@ -355,7 +355,7 @@ procedure key url =
]


clockProcedure : Promise Memory Void
clockProcedure : Promise Memory ()
clockProcedure =
let
modifyClock f =
Expand All @@ -370,7 +370,7 @@ clockProcedure =
]


editAccountFormProcedure : Bucket -> Promise Memory Void
editAccountFormProcedure : Bucket -> Promise Memory ()
editAccountFormProcedure bucket =
Tepa.sequence
[ Tepa.awaitViewEvent
Expand All @@ -381,7 +381,7 @@ editAccountFormProcedure bucket =
]


submitAccountProcedure : Bucket -> Promise Memory Void
submitAccountProcedure : Bucket -> Promise Memory ()
submitAccountProcedure bucket =
let
modifyEditAccountForm f =
Expand Down
8 changes: 4 additions & 4 deletions spa-sample/src/Page/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Json.Encode exposing (Value)
import Mixin exposing (Mixin)
import Mixin.Html as Html exposing (Html)
import Page.Login.Login as Login
import Tepa exposing (Layer, Msg, NavKey, Promise, ViewContext, Void)
import Tepa exposing (Layer, Msg, NavKey, Promise, ViewContext)
import Tepa.Http as Http
import Tepa.Navigation as Nav
import Tepa.Random as Random
Expand Down Expand Up @@ -240,7 +240,7 @@ type alias Bucket =


{-| -}
procedure : NavKey -> AppUrl -> Promise Memory Void
procedure : NavKey -> AppUrl -> Promise Memory ()
procedure key url =
let
bucket =
Expand All @@ -254,7 +254,7 @@ procedure key url =
]


loginFormProcedure : Bucket -> Promise Memory Void
loginFormProcedure : Bucket -> Promise Memory ()
loginFormProcedure bucket =
let
modifyLoginForm f =
Expand Down Expand Up @@ -292,7 +292,7 @@ loginFormProcedure bucket =
]


submitLoginProcedure : Bucket -> Promise Memory Void
submitLoginProcedure : Bucket -> Promise Memory ()
submitLoginProcedure bucket =
let
modifyLoginForm f =
Expand Down
143 changes: 85 additions & 58 deletions spa-sample/src/Widget/Toast.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Widget.Toast exposing
( Memory
, init
, view
, Closed
, ClosedBy(..)
, pushWarning
, pushError
, scenario
Expand All @@ -20,7 +20,7 @@ module Widget.Toast exposing
@docs Memory
@docs init
@docs view
@docs Closed
@docs ClosedBy
# Methods
Expand Down Expand Up @@ -48,7 +48,7 @@ import Expect
import Html.Attributes as Attributes
import Mixin exposing (Mixin)
import Mixin.Html as Html exposing (Html)
import Tepa exposing (Layer, Msg, Promise, Void)
import Tepa exposing (Layer, Msg, Promise)
import Tepa.Scenario as Scenario exposing (Scenario)
import Tepa.Time as Time
import Test.Html.Event as HtmlEvent
Expand Down Expand Up @@ -112,10 +112,17 @@ init =
}


{-| Represents that the popup is closed by user or timeout.
{-| Represents the reason why the popup is closed.
- `ClosedByUser`: Uesr clicked the close button
- `ClosedByTimeout`: The popup was timed out
- `ClosedByLayer`: Layer has expired
-}
type Closed
= Closed
type ClosedBy
= ClosedByUser
| ClosedByTimeout
| ClosedByLayer



Expand All @@ -125,62 +132,73 @@ type Closed
{-| Show warning message.
This promise blocks subsequent processes untill the item is closed.
-}
pushWarning : String -> Promise Memory Closed
pushWarning : String -> Promise Memory ClosedBy
pushWarning =
pushItem WarningMessage


{-| Show error message.
This promise blocks subsequent processes untill the item is closed.
-}
pushError : String -> Promise Memory Closed
pushError : String -> Promise Memory ClosedBy
pushError =
pushItem ErrorMessage


pushItem : MessageType -> String -> Promise Memory Closed
pushItem : MessageType -> String -> Promise Memory ClosedBy
pushItem type_ str =
Tepa.map (\_ -> Closed) <|
Tepa.bind
(Tepa.newLayer
{ isHidden = False
, messageType = type_
, content = str
}
)
<|
\newItem ->
[ Tepa.modify <|
\(Memory m) ->
Memory { m | items = m.items ++ [ newItem ] }
, toastItemProcedure
|> Tepa.onLayer
{ get =
\(Memory m) ->
List.filter (Tepa.isOnSameLayer newItem) m.items
|> List.head
, set =
\new (Memory m) ->
Memory
{ m
| items =
List.map
(\item ->
if Tepa.isOnSameLayer newItem item then
new

else
item
)
m.items
}
}
|> Tepa.void
, Tepa.modify <|
\(Memory m) ->
Memory
{ m | items = List.filter (not << Tepa.isOnSameLayer newItem) m.items }
]
Tepa.bindAndThen
(Tepa.newLayer
{ isHidden = False
, messageType = type_
, content = str
}
)
<|
\newItem ->
Tepa.modify
(\(Memory m) ->
Memory { m | items = m.items ++ [ newItem ] }
)
|> Tepa.andThen
(\_ ->
toastItemProcedure
|> Tepa.onLayer
{ get =
\(Memory m) ->
List.filter (Tepa.isOnSameLayer newItem) m.items
|> List.head
, set =
\new (Memory m) ->
Memory
{ m
| items =
List.map
(\item ->
if Tepa.isOnSameLayer newItem item then
new

else
item
)
m.items
}
}
)
|> Tepa.andThen
(\layerResult ->
case layerResult of
Tepa.LayerOk closedBy ->
Tepa.modify
(\(Memory m) ->
Memory
{ m | items = List.filter (not << Tepa.isOnSameLayer newItem) m.items }
)
|> Tepa.map (\_ -> closedBy)

_ ->
Tepa.succeed ClosedByLayer
)



Expand All @@ -194,18 +212,27 @@ type alias ToastItemMemory =
}


toastItemProcedure : Promise ToastItemMemory Void
toastItemProcedure : Promise ToastItemMemory ClosedBy
toastItemProcedure =
Tepa.sequence
[ Tepa.awaitViewEvent
Tepa.bindAndThen
(Tepa.awaitViewEvent
{ key = keys.toastItemClose
, type_ = "click"
}
|> Tepa.orFaster (Time.sleep toastTimeout)
, Tepa.modify
(\m -> { m | isHidden = True })
, Time.sleep toastFadeOutDuration
]
|> Tepa.map (\_ -> ClosedByUser)
|> Tepa.orFaster
(Time.sleep toastTimeout
|> Tepa.map (\_ -> ClosedByTimeout)
)
)
<|
\closedBy ->
Tepa.sequence
[ Tepa.modify
(\m -> { m | isHidden = True })
, Time.sleep toastFadeOutDuration
]
|> Tepa.map (\_ -> closedBy)



Expand Down
Loading

0 comments on commit 716edf9

Please sign in to comment.