This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the way ports are done to only send tagged messages through …
…one port
- Loading branch information
1 parent
114239d
commit 5011603
Showing
5 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
port module Ports exposing (initBodyProperties, storeLanguage) | ||
module Ports exposing | ||
( initBodyClasses | ||
, storeLanguage | ||
) | ||
|
||
import Ports.Cmd as Cmd | ||
|
||
port initBodyProperties : String -> Cmd msg | ||
|
||
initBodyClasses : String -> Cmd msg | ||
initBodyClasses classes = | ||
Cmd.initBodyClasses classes | ||
|
||
port storeLanguage : String -> Cmd msg | ||
|
||
storeLanguage : String -> Cmd msg | ||
storeLanguage language = | ||
Cmd.storeLanguage language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
port module Ports.Cmd exposing | ||
( initBodyClasses | ||
, storeLanguage | ||
) | ||
|
||
import Json.Encode as Encode exposing (Value) | ||
import Ports.Payload as Payload | ||
|
||
|
||
port outbound : Value -> Cmd msg | ||
|
||
|
||
initBodyClasses : String -> Cmd msg | ||
initBodyClasses classes = | ||
outbound (stringPayload "classes" "INIT_BODY_CLASSES" classes) | ||
|
||
|
||
storeLanguage : String -> Cmd msg | ||
storeLanguage language = | ||
outbound (stringPayload "language" "STORE_LANGUAGE" language) | ||
|
||
|
||
|
||
-- PRIVATE | ||
|
||
|
||
stringPayload : String -> String -> String -> Value | ||
stringPayload objectKey payloadTag string = | ||
let | ||
data : Value | ||
data = | ||
Encode.object [ ( objectKey, Encode.string string ) ] | ||
in | ||
Payload.withTaggedData ( payloadTag, data ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Ports.Payload exposing (withTaggedData) | ||
|
||
import Json.Encode as Encode exposing (Value) | ||
|
||
|
||
withTaggedData : ( String, Value ) -> Value | ||
withTaggedData ( tag, data ) = | ||
Encode.object | ||
[ ( "tag", Encode.string tag ) | ||
, ( "data", data ) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters