Question: Have you considered using web components @samstickland? What JavaScript UI elements are you trying to use?

Asked By
chadtech
Asked At
2018-03-25 15:30:04

Found 15 possible answers.

User Answered At Possible Answer
samstickland 2018-03-25 15:47:24 @chadtech In this instance selectize , but to be honest which Javascript is kind of irrelevant.. I am just trying to learn how this would do done, if the need arrises the level of effort this takes will allow me gauge in the future if this is a sensible thing to do, or if other options are more attractive, incuding but no limited to rewriting the component in Elm
martinsstewart 2018-03-25 15:49:20 Hi, I'm getting the following error
Cannot find variable `BinaryBase64.Octet`.
I've looked at the source for this module https://github.com/newlandsvalley/elm-binary-base64/blob/master/src/BinaryBase64.elm and I'm pretty sure Octet is exposed. (Sorry for the wall of text.) } , subscriptions = always Sub.none , update = update , init = init { view = view Html.program main = main : Program Never Model Msg ---- PROGRAM ---- ] , h1 [] [ text "Your Elm App is working!" ] [ img [ src "/logo.svg" ] [] div [] view model = view : Model -> Html Msg ---- VIEW ---- ( model, Cmd.none ) update msg model = update : Msg -> Model -> ( Model, Cmd Msg ) = NoOp type Msg ---- UPDATE ---- ( {}, Cmd.none ) init = init : ( Model, Cmd Msg ) {} type alias Model = ---- MODEL ---- a = BinaryBase64.Octet 1 import BinaryBase64 import Html.Attributes exposing (src) import Html exposing (Html, text, div, h1, img) BinaryBase64 does not expose Octet .
from this line of code `a = BinaryBase64.Octet 1` in
module Main exposing (..) ^^^^^^^^^^^^^^^^^^ 7| a = BinaryBase64.Octet 1
samstickland 2018-03-25 15:50:24 @martinsstewart It’s not because you don’t expose anything from BinaryBase64 @martinsstewart Can you define a variable outside of a function like that?
martinsstewart 2018-03-25 15:53:31 I don't believe the type annotation is needed (the compiler does give a warning though) a = BinaryBase64.Octet 1
 gives the same error.
At any rate, replacing `a = BinaryBase64.Octet 1` with 
a : BinaryBase64.Octet
pdamoc 2018-03-25 15:55:00 @martinsstewart Octet is a type since it is only an alias
Should work
a = 1
a : BinaryBase64.Octet and you try to use it as a value constructor
martinsstewart 2018-03-25 15:55:47 Oh, duh. Thank you!
chadtech 2018-03-25 16:13:38 @samstickland I would say that what you are describing generally sounds like a use case for web components. And I think web components would be a better way than using ports as you described. You would need your JavaScript to get initiated from ports and hunt down that element and populate it. You could just have JavaScript that is automatically run in that element, if that makes sense. With web components, you can define some custom html element like , and some custom javascript that runs inside the context of that element.
samstickland 2018-03-25 16:16:59 Yep, that makes sense.. I think I will investigate that next @chadtech The interesting thing there is some of the information that the webcomponent could need to render, might still need to come from elm… so ideally the webcomponents could react based on attributes in it’s tag being changed. This is all still exploration at this stage
chadtech 2018-03-25 16:20:45 Yeah, so in my experience, the way to handle that, is to attach the information you want on the attributes of the element. Then your js can read and parse out the json. Where I work we definitely have the attributes changing, and seeing those updates in the html. There could be some deep considerations that went into that I am not aware of however. Something like that. Anyway I think you have the idea. Yeah, the attributes thing is the way to do it. Not sure about the attributes changing tho. I think you could add listeners to your JS for when the attributes change
samstickland 2018-03-25 16:23:34 Cool. I’ll give it a go after I’m finished with this exploration newModel ! [ getStats newModel, trySelectize newModel ] As a return value in update this is going to create a race condition, no?
ilias 2018-03-25 16:30:49 They'll both use the exact same newModel as input for the function. The evaluation order is also defined, but the order in which the resulting commands will actually be executed is not.
samstickland 2018-03-25 16:32:46 yep, that’s what I thought.. so if they both end up producing a new model the last one to execute will overwrite the changes of the first, right?
ilias 2018-03-25 16:36:25 Yeah, though you probably don't want your Msg to contain your Model To be clear - update will always use the model returned by the previous run of update (or init for the first message), so the messages are handled sequentially, with the model being threaded through. Elm does not remember what the model looked like when you created a Cmd _unless_ you explicitly put it in the Msg but rather describe the result of an action or event, so that update can use that together with the current model to give you a nice new model
samstickland 2018-03-25 16:39:53 ok, thanks
josephferano 2018-03-25 17:28:06 How can I enforce rules on the creation of a record? Sorry, I just saw this. I'm was trying to model an area of points, with rows and columns Ah ok, thanks. Sorry, I just saw this. Or just normalizing a Point , as well I have a Point record, but I'd like to have a Direction record that can only be created by taking the normal of 2 points subtracted from each other

Related Questions