A question: I think i might be misunderstanding how commands and actions work together. In the code below, I would like to execute the command (changing the log level for the app) then reload the page ensuring the new log level is displayed. It appears – and I might be mistaken – that the command sometimes runs before the page refresh and sometimes after. It’s always run but sometimes I get the right current level and sometimes not. What is the idiomatic way of dealing with this in Hologram? (And apologies if I’m way off base here, I don’t do much web related programming…)
defmodule MyAppWeb.Hologram.Pages.Logging do
@moduledoc false
use Hologram.Page
require Logger
route "/logging"
layout MyAppWeb.Hologram.Layouts.MainLayout,
header: "Logging"
def init(_params, component, _server) do
component
|> put_state(:current, Logger.level())
end
def action(:set_level, params, component) do
component
|> put_command(:set_level, params)
|> put_page(MyAppWeb.Hologram.Pages.Logging)
end
def command(:set_level, params, server) do
new_level = params.event.value
Logger.configure(level: String.to_atom(new_level))
server
end
end






















