Current section

26 Versions

Jump to

Compare versions

6 files changed
+49 additions
-9 deletions
  @@ -4,6 +4,18 @@ Build rich, interactive UIs entirely in Elixir using Hologram's declarative comp
4 4
5 5 Website: https://hologram.page
6 6
7 + ## Community
8 +
9 + - Elixir Forum: https://elixirforum.com/hologram
10 + - Discord: https://discord.gg/huJWNuqt8J
11 + - Slack: https://elixir-lang.slack.com/channels/hologram
12 +
13 + ## Build in Public
14 +
15 + - LinkedIn: https://www.linkedin.com/in/bartblast/
16 + - X: https://x.com/Bart_Blast
17 + - Bluesky: https://bsky.app/profile/bartblast.com
18 +
7 19 ## Sponsors
8 20
9 21 ### Main Sponsor
  @@ -9,7 +9,7 @@
9 9 {<<"UI">>,<<"https://hologram.page/ui">>},
10 10 {<<"Website">>,<<"https://hologram.page">>}]}.
11 11 {<<"name">>,<<"hologram">>}.
12 - {<<"version">>,<<"0.9.1">>}.
12 + {<<"version">>,<<"0.9.2">>}.
13 13 {<<"description">>,
14 14 <<"Full stack isomorphic Elixir web framework that can be used on top of Phoenix.">>}.
15 15 {<<"elixir">>,<<"~> 1.0">>}.
  @@ -1,6 +1,20 @@
1 1 defmodule Hologram do
2 2 alias Hologram.Reflection
3 3
4 + @doc """
5 + Returns `true` when Hologram's runtime is enabled, `false` otherwise.
6 +
7 + Hologram is always enabled outside of the `:dev` and `:test` environments. In
8 + `:dev` and `:test` it is disabled unless the `HOLOGRAM_START` environment
9 + variable is set to `"1"` (as `mix holo` does). When disabled, Hologram's
10 + supervision children are not started and `Hologram.Router` passes requests
11 + straight through to the next plug instead of trying to serve them.
12 + """
13 + @spec enabled?() :: boolean
14 + def enabled? do
15 + env() not in [:dev, :test] or System.get_env("HOLOGRAM_START") == "1"
16 + end
17 +
4 18 @doc """
5 19 Returns the current environment.
6 20 """
  @@ -13,7 +13,7 @@ defmodule Hologram.Application do
13 13 end
14 14
15 15 defp children(:dev) do
16 - if start_children?() do
16 + if Hologram.enabled?() do
17 17 # credo:disable-for-next-line Credo.Check.Refactor.AppendSingleItem
18 18 base_children() ++ [Hologram.LiveReload]
19 19 else
  @@ -22,7 +22,7 @@ defmodule Hologram.Application do
22 22 end
23 23
24 24 defp children(_env) do
25 - if start_children?() do
25 + if Hologram.enabled?() do
26 26 base_children()
27 27 else
28 28 []
  @@ -41,8 +41,4 @@ defmodule Hologram.Application do
41 41 Hologram.Realtime.Tombstone
42 42 ]
43 43 end
44 -
45 - defp start_children? do
46 - Hologram.env() not in [:dev, :test] or System.get_env("HOLOGRAM_START") == "1"
47 - end
48 44 end
  @@ -1,4 +1,6 @@
1 1 defmodule Hologram.Router do
2 + @moduledoc false
3 +
2 4 use Plug.Router
3 5
4 6 alias Hologram.Controller
  @@ -11,6 +13,20 @@ defmodule Hologram.Router do
11 13 plug :match
12 14 plug :dispatch
13 15
16 + # When Hologram is disabled (see `Hologram.enabled?/0`) its supervision tree -
17 + # including the page module resolver and asset registries that the routes
18 + # below depend on - is not started. Pass the connection straight through to
19 + # the next plug instead of attempting to serve a Hologram route and crashing.
20 + @doc false
21 + @spec call(Plug.Conn.t(), Plug.opts()) :: Plug.Conn.t()
22 + def call(conn, opts) do
23 + if Hologram.enabled?() do
24 + super(conn, opts)
25 + else
26 + conn
27 + end
28 + end
29 +
14 30 post "/hologram/command" do
15 31 Controller.handle_command_request(conn)
16 32 end
  @@ -34,7 +50,9 @@ defmodule Hologram.Router do
34 50 |> halt()
35 51
36 52 _session_id ->
37 - SSE.stream(conn)
53 + conn
54 + |> SSE.stream()
55 + |> halt()
38 56 end
39 57 end
Loading more files…