Commit f5883b9
committed
refactor!: enforce Redux-only state management, remove manual broadcasts
BREAKING CHANGE: Manual broadcast helpers removed, Redux required for LiveView
This commit enforces a cleaner architecture where ALL state updates go through
Redux dispatch actions, eliminating confusion between manual broadcasts and
automatic Redux notifications.
Changes:
- Remove broadcast_state_change/1-2 from :process macro
- Remove session_topic/0 helper from :process macro
- Update Phoenix.SessionProcess.LiveView to work exclusively with Redux PubSub
- Change default state_key from :get_state to :get_redux_state
- Update message format from {:session_state_change, state} to {:redux_state_change, %{state, action, timestamp}}
- Update PubSub topics from "session:*:state" to "session:*:redux"
Breaking Changes:
- Manual broadcast_state_change/1-2 helper removed
- Session processes must use Redux for LiveView integration
- LiveView message format changed
- PubSub topic format changed
Migration Required:
1. Convert session processes to use Redux state management
2. Initialize Redux with PubSub configuration in init/1
3. Update all state mutations to use Redux.dispatch
4. Update LiveView handle_info to match {:redux_state_change, %{state: state}}
5. Update PubSub topics from "session:*:state" to "session:*:redux"
Example:
```elixir
# Session Process
def init(_args) do
redux = Redux.init_state(
%{count: 0},
pubsub: MyApp.PubSub,
pubsub_topic: "session:#{get_session_id()}:redux"
)
{:ok, %{redux: redux}}
end
def handle_call(:increment, _from, state) do
new_redux = Redux.dispatch(state.redux, :increment, &reducer/2)
{:reply, :ok, %{state | redux: new_redux}}
end
# LiveView
def handle_info({:redux_state_change, %{state: state}}, socket) do
{:noreply, assign(socket, count: state.count)}
end
```
Documentation:
- Update CLAUDE.md with Redux-only architecture section
- Update README.md with Redux-based LiveView examples
- Rewrite examples/liveview_integration_example.ex for Redux
- Add TEST_MIGRATION_NOTES.md for test migration guide
Tests:
- Remove test/phoenix/session_process/pubsub_broadcast_test.exs (12 tests)
- Update test/phoenix/session_process/live_view_test.exs (21 tests)
- Update test/phoenix/session_process/live_view_integration_test.exs (16 tests)
- All 164 tests passing
Rationale:
This resolves architectural confusion where users had three overlapping
notification mechanisms (Redux subscriptions, Redux PubSub, manual broadcasts).
Now there is ONE way: Redux.dispatch automatically handles all notifications.1 parent 8894a1e commit f5883b9
File tree
9 files changed
+598
-638
lines changed- examples
- lib/phoenix
- session_process
- test/phoenix/session_process
9 files changed
+598
-638
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
125 | 127 | | |
126 | | - | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
155 | | - | |
156 | | - | |
157 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
158 | 164 | | |
| 165 | + | |
| 166 | + | |
159 | 167 | | |
160 | | - | |
161 | 168 | | |
162 | 169 | | |
163 | 170 | | |
| |||
189 | 196 | | |
190 | 197 | | |
191 | 198 | | |
192 | | - | |
| 199 | + | |
193 | 200 | | |
194 | 201 | | |
195 | 202 | | |
196 | 203 | | |
197 | 204 | | |
| 205 | + | |
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
201 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
202 | 215 | | |
203 | 216 | | |
204 | 217 | | |
205 | 218 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
210 | 222 | | |
211 | 223 | | |
212 | 224 | | |
213 | | - | |
214 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
215 | 234 | | |
216 | 235 | | |
217 | 236 | | |
| |||
223 | 242 | | |
224 | 243 | | |
225 | 244 | | |
226 | | - | |
| 245 | + | |
227 | 246 | | |
228 | 247 | | |
229 | 248 | | |
| |||
232 | 251 | | |
233 | 252 | | |
234 | 253 | | |
235 | | - | |
236 | | - | |
| 254 | + | |
| 255 | + | |
237 | 256 | | |
238 | 257 | | |
239 | 258 | | |
| |||
244 | 263 | | |
245 | 264 | | |
246 | 265 | | |
247 | | - | |
| 266 | + | |
248 | 267 | | |
249 | | - | |
| 268 | + | |
250 | 269 | | |
251 | | - | |
252 | | - | |
253 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
254 | 279 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
259 | 300 | | |
260 | 301 | | |
261 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
156 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
160 | | - | |
161 | | - | |
| 166 | + | |
| 167 | + | |
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
165 | 171 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
173 | 178 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
181 | | - | |
| 193 | + | |
182 | 194 | | |
183 | 195 | | |
184 | 196 | | |
185 | 197 | | |
186 | 198 | | |
187 | 199 | | |
188 | 200 | | |
189 | | - | |
| 201 | + | |
190 | 202 | | |
191 | 203 | | |
192 | 204 | | |
| |||
196 | 208 | | |
197 | 209 | | |
198 | 210 | | |
199 | | - | |
200 | | - | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
225 | 237 | | |
226 | 238 | | |
227 | 239 | | |
| 240 | + | |
| 241 | + | |
228 | 242 | | |
229 | 243 | | |
230 | 244 | | |
| |||
0 commit comments