I’m new to Elm and currently trying to learn the basics. I’ve walked through the Elm guide and am currently experimenting with ports. To get a feeling for Elm and ports I currently try to embed an Elm app into a Jupyter notebook and to “somehow” expose the app model to python.
To be more specific, I’m trying to just embed the simple “up-down counter” example from the Elm-guide in such a way, that the counter value can be set and read from python and - at the same time - changed with the buttons up and down.
You can try my current version on binder (Execute the cells with SHIFT+ENTER one cell at a time, starting from the first) or clone the repository from GitHub (andrebell/PythonJsElm)
which directly maps to the port
port portSetValue : (D.Value -> msg) -> Sub msg
in the Elm code. That works quite fine and allows to write the python code
c.count = 5
to update the Elm model.
The more difficult part is reading the current counter value. Since the port is asynchronously I can request a new value and subscribe with a callback for the value. However, in this case I cannot return the value synchronously with the read attempt. Therefore, I have to hold a shadow copy of the counter value in python to synchronously return the value at any time.
I have two questions here:
- Is it possible to have ports which do not have parameters?
I hope I could explain my attempt. Maybe there is some completely different option I’m missing right now. I would greatly appreciate any comments or advise.
Thanks a lot