Packages

PhoenixLiveState enables LiveView processes to share reactive state across a cluster of nodes. Attach LiveViews to a state server and get automatic assign synchronization.

Current section

Files

Jump to
phoenix_live_state lib phoenix_live_state state_server settings.ex
Raw

lib/phoenix_live_state/state_server/settings.ex

defmodule PhoenixLiveState.StateServer.Settings do
@moduledoc """
Describes the settings of a StateServer.
"""
@moduledoc since: "0.1.0"
alias PhoenixLiveState.StateServer.Policy
alias PhoenixLiveState.StateSpec
defstruct [:ttl, :acl]
@default_ttl 60_000
@type t :: %__MODULE__{
ttl: non_neg_integer(),
acl: Policy.acl()
}
@doc """
Creates a new Settings struct based on the given values.
"""
@spec new(StateSpec.t()) :: t()
def new(%StateSpec{ttl: ttl, acl: acl}) do
%__MODULE__{
ttl: resolve_ttl(ttl || :default),
acl: resolve_acl(acl)
}
end
defp resolve_ttl(:default), do: @default_ttl
defp resolve_ttl(ttl), do: ttl
defp resolve_acl(nil), do: Policy.default_acl()
defp resolve_acl(:default), do: Policy.default_acl()
defp resolve_acl(acl), do: Policy.build_acl!(acl)
end