diff --git a/assets/src/Effect/Command.elm b/assets/src/Effect/Command.elm index c52036a6..718dcfe9 100644 --- a/assets/src/Effect/Command.elm +++ b/assets/src/Effect/Command.elm @@ -35,7 +35,6 @@ type Command msg , data : Value , debounce : Maybe String } - | SetTitle String | NewUrl String | Redirect String | Delay Int msg @@ -121,9 +120,6 @@ map f cmd = PortSend stuff -> PortSend stuff - SetTitle title -> - SetTitle title - NewUrl url -> NewUrl url diff --git a/assets/src/Effect/Program.elm b/assets/src/Effect/Program.elm index f319c7e3..41de87aa 100644 --- a/assets/src/Effect/Program.elm +++ b/assets/src/Effect/Program.elm @@ -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 @@ -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 @@ -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 @@ -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 _ -> @@ -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) diff --git a/assets/src/Effect/Program.js b/assets/src/Effect/Program.js deleted file mode 100644 index 5d6cb939..00000000 --- a/assets/src/Effect/Program.js +++ /dev/null @@ -1,27 +0,0 @@ -export default { - start(app) { - // hack until 0.19 - const shouldPreventDefault = (e) => { - return ((e.metaKey || e.ctrlKey) && e.key === 's') - || ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key === 'd') - || ((e.metaKey || e.ctrlKey) && e.key === ',') - || ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key === 'r') - } - let queue = [] - let callback = null - // window.addEventListener('keydown', (e) => { - // if (e.key === 'Meta' || e.key === 'Control' || e.key === 'Shift') return - // if (shouldPreventDefault(e)) e.preventDefault() - // queue.push(e) - // cancelIdleCallback(callback) - // callback = requestIdleCallback(() => { - // queue.forEach(app.ports.effectProgramKeyDowns.send) - // queue = [] - // }) - // }) - - app.ports.effectProgramTitle.subscribe((title) => { - document.title = title - }) - } -} diff --git a/assets/src/Ellie/Ui/Errors.elm b/assets/src/Ellie/Ui/Errors.elm index 62329cf3..b0bcd7e9 100644 --- a/assets/src/Ellie/Ui/Errors.elm +++ b/assets/src/Ellie/Ui/Errors.elm @@ -19,6 +19,8 @@ view config = Html.styled Html.div [ padding2 zero (px 2) , width (pct 100) + , overflow scroll + , backgroundColor Theme.primaryBackground ] [] [ case config.error of @@ -26,7 +28,6 @@ view config = Html.styled Html.div [ padding (px 12) , marginBottom (px 2) - , backgroundColor Theme.primaryBackground , color Theme.primaryForeground ] [] @@ -62,7 +63,6 @@ viewProblem config problem = Html.styled Html.div [ padding (px 12) , marginBottom (px 2) - , backgroundColor Theme.primaryBackground , color Theme.primaryForeground ] [] diff --git a/assets/src/Network/Absinthe/Socket.js b/assets/src/Network/Absinthe/Socket.js index 021ff6fb..5cd4c60d 100644 --- a/assets/src/Network/Absinthe/Socket.js +++ b/assets/src/Network/Absinthe/Socket.js @@ -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 = () => { @@ -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 => { @@ -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); diff --git a/assets/src/Pages/Editor/index.js b/assets/src/Pages/Editor/index.js index 7867f961..f66899f0 100644 --- a/assets/src/Pages/Editor/index.js +++ b/assets/src/Pages/Editor/index.js @@ -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"; @@ -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); diff --git a/assets/src/Pages/Embed/index.js b/assets/src/Pages/Embed/index.js index 5233aafa..8540b337 100644 --- a/assets/src/Pages/Embed/index.js +++ b/assets/src/Pages/Embed/index.js @@ -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"; @@ -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);