I have a question from another thread - I want to write a package to publish on elm-packages. The task of the package will be to support a certain API provided by the browser and a 3rd party library from the JS ecosystem, so I will have to use ports to communicate with each other elm and JS. The problem for me is the "javascript" part of the code responsible for ports - it is required there to call the function that initializes Elm, and on this instance to call the corresponding methods that communicate with ports. Only as a package developer I have no knowledge of how the end-user initializes Elm (whether he uses an HTML element with id "elm" or another) etc. I have not found valuable information on the web about writing and publishing such packages whose purpose is to provide ports to a specific external JS API. How to do this correctly?
@borkomne5 ай бұрын
What happens if you set 5th element on array of size 3?
@HeyRyanHaskell5 ай бұрын
That's a GREAT question! Something that surprised me when first working with Arrays in Elm (coming from JS) is that you can't set indices past the array's size. So in our specific example if we tried this: Array.set 5 "hi" (Array.fromList [ "ryan", "scott", "alexa" ]) It would NOT insert "hi"! In the next video we cover the "Dict" type: Dict.insert 5 "hi" (Dict.fromList [ (0,"ryan"), (1,"scott"), (2,"alexa") ]) Calling insert on a dictionary works fine! It will add "hi" in the place we expect: Dict.fromList [ (0,"ryan"), (1,"scott"), (2,"alexa"), (5, "hi") ] Hope this explanation makes sense!