Commit 959f713
committed
feat: add Redux subscriptions, selectors, and LiveView integration
Add comprehensive state change subscription system with memoized selectors
and automatic LiveView integration for reactive UIs.
New Features:
- Redux.Selector: Memoized selectors with reselect-style composition
* create_selector/2 for composed selectors with automatic caching
* select/2 for extracting state with memoization
* Recursive selector composition support
* Process-isolated caching for thread safety
* Cache management (clear_cache/0, cache_stats/0)
- Redux.Subscription: State change notification system
* subscribe_to_struct/3 for subscribing to state changes
* Optional selector support for fine-grained notifications
* Shallow equality checks to prevent unnecessary callbacks
* Automatic notification on dispatch/time_travel/reset
* Error handling for failing callbacks and selectors
- Redux.LiveView: LiveView integration helpers
* assign_from_session/3 for automatic assign updates
* subscribe_to_session/2-4 for subscribing to Redux changes
* subscribe_to_pubsub/3 for distributed state listening
* dispatch_to_session/2 and get_session_state/1 helpers
- Phoenix.PubSub Integration:
* enable_pubsub/3 and disable_pubsub/1 for distributed state
* Automatic broadcasting on dispatch when configured
* subscribe_to_broadcasts/3 for cross-node listening
- Redux.ReduxExamples: Comprehensive usage examples
* LiveView integration patterns
* Phoenix Channels examples
* Selectors and subscriptions examples
* PubSub and distributed state examples
Enhancements:
- Redux module:
* Add subscriptions field to Redux struct
* Add pubsub and pubsub_topic fields
* Add subscribe/2-3, unsubscribe/2, notify_subscriptions/1
* Automatic subscription notification after dispatch
* Time travel and reset now notify subscriptions
* Enhanced documentation with comprehensive examples
- Telemetry:
* Add 8 new Redux telemetry events:
- [:phoenix, :session_process, :redux, :dispatch]
- [:phoenix, :session_process, :redux, :subscribe]
- [:phoenix, :session_process, :redux, :unsubscribe]
- [:phoenix, :session_process, :redux, :notification]
- [:phoenix, :session_process, :redux, :selector_cache_hit]
- [:phoenix, :session_process, :redux, :selector_cache_miss]
- [:phoenix, :session_process, :redux, :pubsub_broadcast]
- [:phoenix, :session_process, :redux, :pubsub_receive]
Tests:
- Add 51 comprehensive tests across 3 test files
- Selector tests: 25 tests covering memoization, composition, cache
- Subscription tests: 18 tests covering lifecycle, notifications, errors
- Integration tests: 8 tests covering workflows, performance, recovery
- All tests passing with 100% coverage of new features
Documentation:
- Update README.md with Redux subscription/selector examples
- Update CLAUDE.md with new module descriptions
- Add comprehensive Redux.ReduxExamples module
- Add LiveView and Channels integration examples
- Document all new telemetry events
Dependencies:
- Add phoenix_pubsub ~> 2.1 for distributed state support
Breaking Changes: None
Files Changed:
- 7 new files (4 modules + 3 test files)
- 6 modified files (Redux, Telemetry, docs, mix.exs)
- +3,466 lines total1 parent 46408c5 commit 959f713
File tree
13 files changed
+3466
-25
lines changed- lib/phoenix/session_process
- redux
- test/phoenix/session_process
- redux
13 files changed
+3466
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
109 | 113 | | |
110 | 114 | | |
111 | 115 | | |
112 | | - | |
| 116 | + | |
113 | 117 | | |
114 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
404 | 570 | | |
405 | 571 | | |
406 | 572 | | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
407 | 577 | | |
408 | 578 | | |
409 | | - | |
| 579 | + | |
410 | 580 | | |
411 | | - | |
| 581 | + | |
412 | 582 | | |
413 | 583 | | |
414 | 584 | | |
| |||
451 | 621 | | |
452 | 622 | | |
453 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
454 | 634 | | |
455 | 635 | | |
456 | 636 | | |
| |||
0 commit comments