Is there a better way to inject Elixir variables than serializing them into strings and injecting them into DenoRider.eval? I’m doing this currently.
defmodule GraphFxJS do
@moduledoc """
This module is used to run a JavaScript function on a graph, using DenoRider.
The graph has keys "nodes" and "edges".
The graph_fn is a JavaScript string like:
"""
def run(graph, graph_fn) do
graph_json = Jason.encode!(graph)
# Call the graph_fn with the graph_json as an argument
# i.e. IIFE pattern
js = "(#{graph_fn})(#{graph_json})"
case DenoRider.eval(js) do
{:ok, result} ->
result
other ->
raise "Error running graph_fn: #{inspect(other)}"
end
end
end


















