I’ve started learning how to use Phoenix and Elixir recently, and I’m trying to figure out how to do the following:
- Send text information from Phoenix to JS.
- Have the JS compute the dimensions of the text using browser APIs. (I know how to do this step.)
- Send the dimension info from JS to Phoenix.
- Have Phoenix use this information to record a “final” state. (I have an algorithm for this step.)
- Have Phoenix render the state to HTML. (This step is easy.)
I read the JavaScript interop page, but couldn’t figure out how to accomplish steps 1 and 3. Right now, step 4 is running in the view’s mount
function (warning: ugly code), so I think I need to be able to do steps 1-3 during mount
.
More context: I’m trying to create some boxes of text and arrange them in a DAG using absolute positioning. One of the inputs to the positioning algorithm is the height of the text boxes. Right now, for testing, I’m using hard-coded heights. For actual use, I’d like to get those from the browser since the height can depend on the user’s font settings etc.
Any suggestions on how I can accomplish steps 1 and 3?