Skip to content

Commit

Permalink
Additional 0.19 cleanup and fix error section scrolling (#81)
Browse files Browse the repository at this point in the history
* chore(*): rm unnecessary effects, cleanup socket code

* fix(Ellie.Ui.Error): mv bg color up, wrap view in overflow scroll
  • Loading branch information
tbash authored Feb 3, 2019
1 parent e311b93 commit 10910bf
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 129 deletions.
4 changes: 0 additions & 4 deletions assets/src/Effect/Command.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Command msg
, data : Value
, debounce : Maybe String
}
| SetTitle String
| NewUrl String
| Redirect String
| Delay Int msg
Expand Down Expand Up @@ -121,9 +120,6 @@ map f cmd =
PortSend stuff ->
PortSend stuff

SetTitle title ->
SetTitle title

NewUrl url ->
NewUrl url

Expand Down
151 changes: 65 additions & 86 deletions assets/src/Effect/Program.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
port module Effect.Program exposing (Config, Model(..), Msg(..), Program, State, debounceConfig, effectProgramKeyDowns, effectProgramTitle, includeTitle, initialState, keyDownDecoder, maybeWithDebounce, maybeWithToken, program, runCmd, runSub, withCaching, wrapInit, wrapSubscriptions, wrapUpdate, wrapView)
port module Effect.Program exposing (Config, Model(..), Msg(..), Program, State, debounceConfig, effectProgramKeyDowns, initialState, keyDownDecoder, maybeWithDebounce, maybeWithToken, program, runCmd, runSub, withCaching, wrapInit, wrapSubscriptions, wrapUpdate, wrapView)

import Browser
import Browser.Events
Expand Down Expand Up @@ -31,9 +31,6 @@ import Url exposing (Url)
port effectProgramKeyDowns : (Decode.Value -> a) -> Sub a


port effectProgramTitle : String -> Cmd a


type alias Config flags route model msg =
{ init : flags -> route -> ( model, Command msg )
, url : Url -> route
Expand Down Expand Up @@ -164,11 +161,6 @@ runCmd config state cmd =
)
|> maybeWithDebounce state debounce

Command.SetTitle title ->
( state
, effectProgramTitle title
)

Command.PortSend stuff ->
config.outbound ( stuff.channel, stuff.data )
|> maybeWithDebounce state stuff.debounce
Expand Down Expand Up @@ -318,7 +310,7 @@ wrapInit config flagsValue url navKey =
runCmd config (initialState navKey) userCmd
in
( Running state flags userModel
, Cmd.batch [ cmd, effectProgramTitle (config.title userModel) ]
, cmd
)

Err _ ->
Expand All @@ -329,85 +321,72 @@ wrapInit config flagsValue url navKey =

wrapUpdate : Config flags route model msg -> Msg msg -> Model flags model msg -> ( Model flags model msg, Cmd (Msg msg) )
wrapUpdate config msg model =
includeTitle config.title <|
case model of
StartupFailure ->
( model, Cmd.none )

Running state flags m ->
case msg of
Debounce name debounceMsg ->
state.debouncers
|> Dict.get name
|> Maybe.map (Debounce.update (debounceConfig (Debounce name)) (Debounce.takeLast identity) debounceMsg)
|> Maybe.map (Tuple.mapFirst (\debouncer -> Running { state | debouncers = Dict.insert name debouncer state.debouncers } flags m))
|> Maybe.withDefault ( model, Cmd.none )

NoOp ->
( model, Cmd.none )

KeyDown key ->
( Running { state | keysDown = Set.insert key state.keysDown } flags m
, Cmd.none
)

KeyUp key ->
( Running { state | keysDown = Set.remove key state.keysDown } flags m
, Cmd.none
)

UserMsg userMsg ->
let
( userModel, userCmd ) =
config.update flags userMsg m

( newState, cmd ) =
runCmd config state userCmd
in
( Running newState flags userModel
, cmd
)

SetupSocket key socketConfig selection ->
let
( absinthe, absintheCmd ) =
Absinthe.init socketConfig always selection
in
( Running
{ state | sockets = Dict.insert key absinthe state.sockets }
flags
m
, absintheCmd
)

SubscriptionMsg key socketMsg ->
case Dict.get key state.sockets of
Just socket ->
let
( newSocket, socketCmd ) =
Absinthe.update socketMsg socket
in
( Running
{ state | sockets = Dict.insert key newSocket state.sockets }
flags
m
, Cmd.map (SubscriptionMsg key) socketCmd
)

Nothing ->
( model, Cmd.none )


includeTitle : (model -> String) -> ( Model flags model msg, Cmd (Msg msg) ) -> ( Model flags model msg, Cmd (Msg msg) )
includeTitle produceTitle ( model, cmd ) =
case model of
StartupFailure ->
( model, cmd )
( model, Cmd.none )

Running state flags m ->
case msg of
Debounce name debounceMsg ->
state.debouncers
|> Dict.get name
|> Maybe.map (Debounce.update (debounceConfig (Debounce name)) (Debounce.takeLast identity) debounceMsg)
|> Maybe.map (Tuple.mapFirst (\debouncer -> Running { state | debouncers = Dict.insert name debouncer state.debouncers } flags m))
|> Maybe.withDefault ( model, Cmd.none )

NoOp ->
( model, Cmd.none )

KeyDown key ->
( Running { state | keysDown = Set.insert key state.keysDown } flags m
, Cmd.none
)

Running _ _ m ->
( model
, Cmd.batch [ cmd, effectProgramTitle (produceTitle m) ]
)
KeyUp key ->
( Running { state | keysDown = Set.remove key state.keysDown } flags m
, Cmd.none
)

UserMsg userMsg ->
let
( userModel, userCmd ) =
config.update flags userMsg m

( newState, cmd ) =
runCmd config state userCmd
in
( Running newState flags userModel
, cmd
)

SetupSocket key socketConfig selection ->
let
( absinthe, absintheCmd ) =
Absinthe.init socketConfig always selection
in
( Running
{ state | sockets = Dict.insert key absinthe state.sockets }
flags
m
, absintheCmd
)

SubscriptionMsg key socketMsg ->
case Dict.get key state.sockets of
Just socket ->
let
( newSocket, socketCmd ) =
Absinthe.update socketMsg socket
in
( Running
{ state | sockets = Dict.insert key newSocket state.sockets }
flags
m
, Cmd.map (SubscriptionMsg key) socketCmd
)

Nothing ->
( model, Cmd.none )


wrapView : Config flags route model msg -> Model flags model msg -> Browser.Document (Msg msg)
Expand Down
27 changes: 0 additions & 27 deletions assets/src/Effect/Program.js

This file was deleted.

4 changes: 2 additions & 2 deletions assets/src/Ellie/Ui/Errors.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ view config =
Html.styled Html.div
[ padding2 zero (px 2)
, width (pct 100)
, overflow scroll
, backgroundColor Theme.primaryBackground
]
[]
[ case config.error of
Error.GeneralProblem { title, message } ->
Html.styled Html.div
[ padding (px 12)
, marginBottom (px 2)
, backgroundColor Theme.primaryBackground
, color Theme.primaryForeground
]
[]
Expand Down Expand Up @@ -62,7 +63,6 @@ viewProblem config problem =
Html.styled Html.div
[ padding (px 12)
, marginBottom (px 2)
, backgroundColor Theme.primaryBackground
, color Theme.primaryForeground
]
[]
Expand Down
9 changes: 3 additions & 6 deletions assets/src/Network/Absinthe/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { Socket as PhoenixSocket } from "phoenix";
const createPhoenixSocket = (address, params) =>
new PhoenixSocket(address, { params });

const createAbsintheSocket = phoenixSocket =>
AbsintheSocket.create(phoenixSocket);

export default {
start(app) {
const onOpen = () => {
Expand All @@ -25,8 +22,8 @@ export default {
app.ports.absintheSocketInbound.send({ tag: "Error" });
};

const onResult = res => {
app.ports.absintheSocketInbound.send({ tag: "Data", data: res });
const onResult = data => {
app.ports.absintheSocketInbound.send({ tag: "Data", data });
};

app.ports.absintheSocketOutbound.subscribe(data => {
Expand All @@ -35,7 +32,7 @@ export default {
const phoenixSocket = createPhoenixSocket(data.url, {
token: data.token
});
const absintheSocket = createAbsintheSocket(phoenixSocket);
const absintheSocket = AbsintheSocket.create(phoenixSocket);

phoenixSocket.onOpen(onOpen);

Expand Down
2 changes: 0 additions & 2 deletions assets/src/Pages/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import NetworkAbsintheSocket from "../../Network/Absinthe/Socket";
import EffectProgram from "../../Effect/Program";
import EllieUiIcon from "../../Ellie/Ui/Icon";
import EllieUiMenu from "../../Ellie/Ui/Menu";
import EllieUiCopyText from "../../Ellie/Ui/CopyText";
Expand All @@ -39,7 +38,6 @@ document.addEventListener("DOMContentLoaded", () => {
const app = Elm.Pages.Editor.Main.init({ flags });

NetworkAbsintheSocket.start(app);
EffectProgram.start(app);
EllieUiIcon.start(app);
EllieUiMenu.start(app);
EllieUiCopyText.start(app);
Expand Down
2 changes: 0 additions & 2 deletions assets/src/Pages/Embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import EllieUiCodeEditor from "../../Ellie/Ui/CodeEditor";
import EllieUiOutput from "../../Ellie/Ui/Output";
import EllieConstants from "../../Ellie/Constants";
import NetworkAbsintheSocket from "../../Network/Absinthe/Socket";
import EffectProgram from "../../Effect/Program";
import PagesEmbedMain from "./Main";
import "../../Ellie/Ui/CodeEditor.css";
import "../../Ellie/Ui/Logo.css";
Expand All @@ -17,7 +16,6 @@ document.addEventListener("DOMContentLoaded", () => {
const app = Elm.Pages.Embed.Main.init({ flags });

NetworkAbsintheSocket.start(app);
EffectProgram.start(app);
EllieUiOutput.start(app);
EllieUiCodeEditor.start(app);
EllieUiIcon.start(app);
Expand Down

0 comments on commit 10910bf

Please sign in to comment.