Skip to content

Commit ac420cd

Browse files
committed
fix: resolve all Dialyzer type checking errors
- Add @type t definition for Redux struct with proper field types - Replace Phoenix.LiveView.Socket.t() with term() for optional dependency - Split subscribe/2 and subscribe/3 into separate clauses to avoid default parameter issues with Dialyzer Dialyzer now passes with 0 errors.
1 parent 3ebfe78 commit ac420cd

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

lib/phoenix/session_process/redux.ex

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ defmodule Phoenix.SessionProcess.Redux do
158158
@type reducer :: (state(), action() -> state())
159159
@type middleware :: (action(), state(), (action() -> state()) -> state())
160160

161+
@type t :: %__MODULE__{
162+
current_state: state(),
163+
initial_state: state(),
164+
history: list({action(), state()}),
165+
reducer: reducer() | nil,
166+
middleware: list(middleware()),
167+
max_history_size: non_neg_integer(),
168+
pubsub: module() | nil,
169+
pubsub_topic: binary() | nil,
170+
subscriptions: list(map())
171+
}
172+
161173
@doc """
162174
The Redux state structure containing current state and action history.
163175
"""
@@ -461,17 +473,15 @@ defmodule Phoenix.SessionProcess.Redux do
461473
462474
"""
463475
@spec subscribe(%__MODULE__{}, function()) :: %__MODULE__{}
464-
@spec subscribe(%__MODULE__{}, function(), function()) :: %__MODULE__{}
465-
def subscribe(redux, selector_or_callback, callback \\ nil) do
476+
def subscribe(redux, callback) when is_function(callback, 1) do
466477
alias Phoenix.SessionProcess.Redux.Subscription
478+
{redux, _sub_id} = Subscription.subscribe_to_struct(redux, nil, callback)
479+
redux
480+
end
467481

468-
{selector, callback} =
469-
if callback do
470-
{selector_or_callback, callback}
471-
else
472-
{nil, selector_or_callback}
473-
end
474-
482+
@spec subscribe(%__MODULE__{}, function() | map(), function()) :: %__MODULE__{}
483+
def subscribe(redux, selector, callback) when is_function(callback, 1) do
484+
alias Phoenix.SessionProcess.Redux.Subscription
475485
{redux, _sub_id} = Subscription.subscribe_to_struct(redux, selector, callback)
476486
redux
477487
end

lib/phoenix/session_process/redux/live_view.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
118118
end
119119
120120
"""
121-
@spec subscribe_to_session(Phoenix.LiveView.Socket.t(), String.t()) ::
122-
Phoenix.LiveView.Socket.t()
121+
@spec subscribe_to_session(term(), String.t()) ::
122+
term()
123123
def subscribe_to_session(socket, session_id) do
124124
subscribe_to_session(socket, session_id, nil, fn state ->
125125
send(self(), {:redux_state_change, state})
@@ -141,11 +141,11 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
141141
142142
"""
143143
@spec subscribe_to_session(
144-
Phoenix.LiveView.Socket.t(),
144+
term(),
145145
String.t(),
146146
Selector.selector() | nil,
147147
function()
148-
) :: Phoenix.LiveView.Socket.t()
148+
) :: term()
149149
def subscribe_to_session(socket, session_id, selector, callback) do
150150
# Get the Redux state from session process
151151
case SessionProcess.call(session_id, :get_redux_state) do
@@ -183,10 +183,10 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
183183
184184
"""
185185
@spec assign_from_session(
186-
Phoenix.LiveView.Socket.t(),
186+
term(),
187187
String.t(),
188188
%{atom() => Selector.selector()}
189-
) :: Phoenix.LiveView.Socket.t()
189+
) :: term()
190190
def assign_from_session(socket, session_id, selectors) do
191191
Enum.reduce(selectors, socket, fn {assign_key, selector}, acc_socket ->
192192
subscribe_to_session(acc_socket, session_id, selector, fn value ->
@@ -210,8 +210,8 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
210210
end
211211
212212
"""
213-
@spec subscribe_to_pubsub(Phoenix.LiveView.Socket.t(), module(), String.t()) ::
214-
Phoenix.LiveView.Socket.t()
213+
@spec subscribe_to_pubsub(term(), module(), String.t()) ::
214+
term()
215215
def subscribe_to_pubsub(socket, pubsub_module, topic) do
216216
Phoenix.PubSub.subscribe(pubsub_module, topic)
217217
socket
@@ -229,8 +229,8 @@ defmodule Phoenix.SessionProcess.Redux.LiveView do
229229
end
230230
231231
"""
232-
@spec handle_assign_update(Phoenix.LiveView.Socket.t(), atom(), any()) ::
233-
Phoenix.LiveView.Socket.t()
232+
@spec handle_assign_update(term(), atom(), any()) ::
233+
term()
234234
def handle_assign_update(socket, assign_key, value) do
235235
if Code.ensure_loaded?(Phoenix.Component) do
236236
# credo:disable-for-next-line Credo.Check.Refactor.Apply

0 commit comments

Comments
 (0)