| -- Copyright 2020 The Fuchsia Authors. All rights reserved. |
| -- Use of this source code is governed by a BSD-style license that can be |
| -- found in the LICENSE file. |
| |
| |
| port module Ports exposing |
| ( applySettings |
| , clearDataAndReload |
| , persistModel |
| , resizeEditors |
| , setMainTabEnabled |
| , updateEditors |
| ) |
| |
| {-| This module defines ports for communicating with JavaScript. |
| -} |
| |
| import Json.Encode as Encode |
| |
| |
| {-| Sends a value to JavaScript. This is the only port. |
| -} |
| port out : Encode.Value -> Cmd msg |
| |
| |
| command : String -> Encode.Value -> Cmd msg |
| command cmd value = |
| out <| |
| Encode.object |
| [ ( "command", Encode.string cmd ) |
| , ( "payload", value ) |
| ] |
| |
| |
| persistModel : Encode.Value -> Cmd msg |
| persistModel model = |
| command "persistModel" model |
| |
| |
| clearDataAndReload : Cmd msg |
| clearDataAndReload = |
| command "clearDataAndReload" Encode.null |
| |
| |
| applySettings : Encode.Value -> Cmd msg |
| applySettings settings = |
| command "applySettings" settings |
| |
| |
| setMainTabEnabled : Bool -> Cmd msg |
| setMainTabEnabled enabled = |
| command "setMainTabEnabled" (Encode.bool enabled) |
| |
| |
| updateEditors : Encode.Value -> Encode.Value -> Encode.Value -> Cmd msg |
| updateEditors inputMode outputMode options = |
| command "updateEditors" <| |
| Encode.object |
| [ ( "input", inputMode ) |
| , ( "output", outputMode ) |
| , ( "options", options ) |
| ] |
| |
| |
| resizeEditors : Cmd msg |
| resizeEditors = |
| command "resizeEditors" Encode.null |