phlex-reactive 0.16.14 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +118 -22
- data/README.md +72 -0
- data/app/javascript/phlex/reactive/core.js +1 -0
- data/app/javascript/phlex/reactive/core.min.js +6 -6
- data/app/javascript/phlex/reactive/core.min.js.map +4 -4
- data/app/javascript/phlex/reactive/features/presence.js +37 -3
- data/app/javascript/phlex/reactive/features/presence.min.js +2 -2
- data/app/javascript/phlex/reactive/features/presence.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/subscribe.js +188 -0
- data/app/javascript/phlex/reactive/features/subscribe.min.js +4 -0
- data/app/javascript/phlex/reactive/features/subscribe.min.js.map +10 -0
- data/app/javascript/phlex/reactive/reactive_controller.js +2 -0
- data/app/javascript/phlex/reactive/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +7 -6
- data/app/javascript/phlex/reactive/runtime.js +25 -1
- data/lib/phlex/reactive/component/dsl.rb +3 -0
- data/lib/phlex/reactive/component/helpers.rb +8 -0
- data/lib/phlex/reactive/component/presence_declaration.rb +2 -1
- data/lib/phlex/reactive/component/registry.rb +5 -2
- data/lib/phlex/reactive/component/subscribe_declaration.rb +132 -0
- data/lib/phlex/reactive/component.rb +1 -0
- data/lib/phlex/reactive/doctor.rb +51 -4
- data/lib/phlex/reactive/engine.rb +3 -3
- data/lib/phlex/reactive/subscribe.rb +150 -0
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91678969419d0d4fcb917d69f7d1c9e7478877317e8c98e84dfec78fcbf114ca
|
|
4
|
+
data.tar.gz: 79b1ab20debf6de7a3c7c80752b15a6bfab89848276fd75ddbadafa0161b7886
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4050cef0a111c227ffb5c722e004fed6604e0c63f30cae2ad9f599366aeec956f0bd6776095f963bb9457fd266e782832c0b885e2006e0f9b143de8005c1b6f0
|
|
7
|
+
data.tar.gz: cab2bcfb72b76b907e614b248a342bdad48c5c70ca2f447d10767a262676a02c5173f0dec899328d8c1f84ab9db85914d8651f529f1cb198abb3169b472d2726
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,86 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.18.0] - 2026-11-16
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`reactive_subscribe` catches up on a broadcast sent before its source
|
|
14
|
+
connected (#478, pgbus).** On a durable stream the root carries the stream's
|
|
15
|
+
watermark at render (`data-reactive-subscribe-since`, read as
|
|
16
|
+
`pgbus_stream_from` reads it: one `MAX(msg_id)` query per render of a durable
|
|
17
|
+
subscribing root), and the minted `<pgbus-stream-source>` opens with it as
|
|
18
|
+
`since-id`. A broadcast sent between the render and the connection now
|
|
19
|
+
arrives. Roots sharing a source take the lowest watermark, and a source minted
|
|
20
|
+
again after a page render opens from its roots' watermarks then: it never
|
|
21
|
+
skips a frame, but it may replay one a root already shows, so a `js:` or
|
|
22
|
+
append frame can apply twice. A `data-turbo-permanent` subscribing root hits
|
|
23
|
+
this on every Drive visit (its source is minted again each time, from the
|
|
24
|
+
root's first render). Each time a
|
|
25
|
+
root's source connects, the root gets `reactive:subscribed`
|
|
26
|
+
(`detail: { connectionId, reconnect }`, not bubbling), so
|
|
27
|
+
`on(:refresh, event: "reactive:subscribed")` refetches what an ephemeral
|
|
28
|
+
stream cannot replay.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **A `reactive_subscribe` stream durable by configuration no longer replays
|
|
33
|
+
frames older than the render (#478).** The source opened with no `since`, which pgbus reads as
|
|
34
|
+
0, so it replayed every retained frame: a `js:` broadcast sent before the
|
|
35
|
+
page rendered ran again on load.
|
|
36
|
+
|
|
37
|
+
## [0.17.0] - 2026-11-16
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- **`reactive_subscribe` — a component that subscribes to its own broadcast
|
|
42
|
+
stream (#474, pgbus).** `reactive_subscribe :status` (the stream
|
|
43
|
+
`[record, :status]`) or `reactive_subscribe key: [...]` / `key: -> { [...] }`
|
|
44
|
+
puts the stream's signed pgbus source on the root. The new `subscribe` client
|
|
45
|
+
feature keeps one `<pgbus-stream-source>` for it while the root is on the
|
|
46
|
+
page. A morph that keeps the key keeps the connection, and roots on the same
|
|
47
|
+
key share one source. `Widget.broadcast_self(replace: record)` broadcasts to
|
|
48
|
+
the declared stream, so no view repeats the key in a `turbo_stream_from`. An
|
|
49
|
+
action on a subscribing root sends that root's own connection id as
|
|
50
|
+
`X-Pgbus-Connection`, so `exclude: reactive_connection_id` skips the actor on
|
|
51
|
+
that stream but no longer on another page-level stream. On Action Cable a subscribing root raises
|
|
52
|
+
`ConfigurationError` at render, naming `turbo_stream_from`. A stream name over
|
|
53
|
+
pgbus's budget is refused at render. The doctor checks for pgbus and for an
|
|
54
|
+
import of its client element.
|
|
55
|
+
- **conformance-kit 0.5, with its report-only Ractorize job (#363).** CI's
|
|
56
|
+
conformance workflow and the Gemfiles move to 0.5. `.conformance.yml` sets
|
|
57
|
+
`ractorize:`: the dummy boots in production on Rails main,
|
|
58
|
+
`Rails.application.ractorize!` runs, `/up` and `/counter` are each served
|
|
59
|
+
inside a non-main Ractor, and the audit runs again. The job never fails the
|
|
60
|
+
build. As of phlex-rails 2.4.0, `/counter` stops in its `render_in`, which
|
|
61
|
+
does not take Rails main's `locals:` (fixed on phlex-rails main,
|
|
62
|
+
yippee-fun/phlex-rails#332, unreleased). The dummy gains a production
|
|
63
|
+
environment for it and skips its test-only `Viewer` gate there. 0.5.1 caps
|
|
64
|
+
prism below 2 in that job's bundle: with prism 2, refract 1.1.0 (which Phlex
|
|
65
|
+
loads) fails at boot on `Prism::MissingNode` (yippee-fun/refract#6).
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- **A per-render dormant presence roster raised nothing and never joined (#474's
|
|
70
|
+
review).** `reactive_root(dormant: true)` on a `reactive_presence` root (or a
|
|
71
|
+
`reactive_subscribe` one) rendered a root that never connects, so the tab never
|
|
72
|
+
joined. That render now raises the `ArgumentError` a class-level
|
|
73
|
+
`reactive_dormant` already raises when the class loads. An app that rendered
|
|
74
|
+
the combination gets the error on that page and drops `dormant: true` for that
|
|
75
|
+
root.
|
|
76
|
+
- **A page refresh by morph dropped a presence root's subscription (#474's
|
|
77
|
+
review).** Turbo 8's page morph removes the `<pgbus-stream-source>` the client
|
|
78
|
+
minted in `<body>` while the roster root stays connected, so the tab left the
|
|
79
|
+
roster for good. The minted sources now sit in one hidden,
|
|
80
|
+
`data-turbo-permanent` `<reactive-stream-sources>` box at the end of `<body>`,
|
|
81
|
+
so the morph keeps them (and never pairs the box with a source the refreshed
|
|
82
|
+
page adds) and the tab keeps its seat. Should a render drop it anyway, the client
|
|
83
|
+
mints a fresh source for every presence root still on the page, and its
|
|
84
|
+
`pgbus:connected` announces the tab again. `reactive_subscribe` sources do the
|
|
85
|
+
same.
|
|
86
|
+
|
|
87
|
+
## [0.16.14] - 2026-11-12
|
|
88
|
+
|
|
9
89
|
### Added
|
|
10
90
|
|
|
11
91
|
- **`js.click(to = :trigger)` (#471).** A client op that activates an element
|
|
@@ -18,17 +98,19 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
18
98
|
`reply.js`, a settle's `js` and `broadcast_to(js:)` refuse it.
|
|
19
99
|
`on_client(:click, js.click)` on its own trigger raises at render (the
|
|
20
100
|
synthetic click re-enters its own binding, which prevents its default).
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
101
|
+
|
|
102
|
+
### Changed
|
|
103
|
+
|
|
104
|
+
- **BREAKING (minor release): `reactive_editable(on_enter:)` raises on an op
|
|
105
|
+
that names `:trigger` (#471).** The Enter runs its ops with no trigger element, so an op such as
|
|
106
|
+
`js.blur(:trigger)`, `js.add_class(:trigger, …)` or a bare `js.click` did
|
|
107
|
+
nothing; it now raises `ArgumentError` at render. Name the element with a
|
|
108
|
+
CSS selector.
|
|
109
|
+
|
|
110
|
+
## [0.16.13] - 2026-11-08
|
|
111
|
+
|
|
112
|
+
### Added
|
|
113
|
+
|
|
32
114
|
- **`reactive_nested_add(clear: :reset)` (#466).** `clear: true` empties every
|
|
33
115
|
fill-then-add source after an add, so a checkbox that renders ticked was
|
|
34
116
|
unticked for every row after the first. `clear: :reset` puts each source back
|
|
@@ -41,17 +123,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
41
123
|
|
|
42
124
|
### Changed
|
|
43
125
|
|
|
44
|
-
- **BREAKING (minor release): `reactive_editable(on_enter:)` raises on an op
|
|
45
|
-
that names `:trigger` (#471).** The Enter runs its ops with no trigger element, so an op such as
|
|
46
|
-
`js.blur(:trigger)`, `js.add_class(:trigger, …)` or a bare `js.click` did
|
|
47
|
-
nothing; it now raises `ArgumentError` at render. Name the element with a
|
|
48
|
-
CSS selector.
|
|
49
|
-
|
|
50
126
|
- **`reactive_nested_add(clear:)` raises on an unknown value (#466).** It takes
|
|
51
127
|
`true`, `false`, `nil` or `:reset`; anything else (a truthy string such as
|
|
52
128
|
`clear: "yes"`, which used to act as `true`) now raises `ArgumentError` at
|
|
53
129
|
render. Pass `clear: true`.
|
|
54
|
-
|
|
55
130
|
- **`reactive:idle` reports what failed (#464).** Each busy window (from the
|
|
56
131
|
`reactive:busy` edge to the `reactive:idle` edge) collects every failure raised
|
|
57
132
|
inside it: a dispatch that failed (`http`, `timeout`, `network`, `offline`,
|
|
@@ -64,9 +139,6 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
64
139
|
`apply` too (after `reactive:applied`; the drawn rest of the reply is not
|
|
65
140
|
reverted). A render still running when the action timeout cuts the wait off
|
|
66
141
|
is not recorded.
|
|
67
|
-
|
|
68
|
-
### Changed
|
|
69
|
-
|
|
70
142
|
- **BREAKING (minor release): `wait_for_reactive` raises when the round trip
|
|
71
143
|
failed (#464).** It used to return after a 500, a timeout or a redirect just as
|
|
72
144
|
after a rendered reply, and the next assertion failed a full Capybara wait
|
|
@@ -98,6 +170,25 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
98
170
|
- **A client-side apply failure now marks the root (#464).** The `kind: "apply"`
|
|
99
171
|
error emitted `reactive:error` but never set `data-reactive-error`; it now sets
|
|
100
172
|
`data-reactive-error="apply"` like every other failure kind.
|
|
173
|
+
|
|
174
|
+
## [0.16.12] - 2026-10-31
|
|
175
|
+
|
|
176
|
+
### Added
|
|
177
|
+
|
|
178
|
+
- **`:strict_integer` and `:strict_float` param types (#460).** `:integer` and
|
|
179
|
+
`:float` cast with `to_i`/`to_f`, so a cleared number field reaches the action
|
|
180
|
+
as `0` and `"12abc"` as `12`, and an action cannot tell a blank field from a
|
|
181
|
+
typed `0`. The two new built-ins follow the drop contract instead: a blank or
|
|
182
|
+
unparsable value is dropped, so the keyword default applies. `:strict_integer`
|
|
183
|
+
is `Integer(value, 10)`, so `"1.5"`, a JSON `1.0` and `"0x10"` drop and `"010"`
|
|
184
|
+
is `10`; `:strict_float` reads decimal notation, so it also drops hex and a
|
|
185
|
+
string too large or too small for a Float (`"1e400"`, `"1e-400"`). Both take a JSON number
|
|
186
|
+
as well as a string,
|
|
187
|
+
and work in nested and array schemas, where a dropped element follows the
|
|
188
|
+
existing array rule. `:integer` and `:float` are unchanged.
|
|
189
|
+
|
|
190
|
+
### Fixed
|
|
191
|
+
|
|
101
192
|
- **The docs now say what `:integer` and `:float` do (#460).** The Actions &
|
|
102
193
|
events guide and the counter example said a non-numeric value is dropped; it
|
|
103
194
|
never was. Both pages, and the README, now describe `to_i`/`to_f` and point at
|
|
@@ -4567,7 +4658,12 @@ room for dogfood fixes.
|
|
|
4567
4658
|
scaffolds a reactive component (and an RSpec spec when the app uses RSpec),
|
|
4568
4659
|
state-backed by default or record-backed with `--record`.
|
|
4569
4660
|
|
|
4570
|
-
[Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.
|
|
4661
|
+
[Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.18.0...HEAD
|
|
4662
|
+
[0.18.0]: https://github.com/mhenrixon/phlex-reactive/compare/v0.17.0...v0.18.0
|
|
4663
|
+
[0.17.0]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.14...v0.17.0
|
|
4664
|
+
[0.16.14]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.13...v0.16.14
|
|
4665
|
+
[0.16.13]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.12...v0.16.13
|
|
4666
|
+
[0.16.12]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.11...v0.16.12
|
|
4571
4667
|
[0.16.11]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.10...v0.16.11
|
|
4572
4668
|
[0.16.10]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.9...v0.16.10
|
|
4573
4669
|
[0.16.9]: https://github.com/mhenrixon/phlex-reactive/compare/v0.16.8...v0.16.9
|
data/README.md
CHANGED
|
@@ -2371,6 +2371,78 @@ end
|
|
|
2371
2371
|
`Phlex::Reactive::PresenceRenderJob` (on `defer_job_queue`), so the app needs
|
|
2372
2372
|
an ActiveJob adapter that runs jobs. A state change renders in the action.
|
|
2373
2373
|
|
|
2374
|
+
### A component that subscribes to its own stream (`reactive_subscribe`)
|
|
2375
|
+
|
|
2376
|
+
With pgbus, a component declares the broadcast stream it listens to. A job's
|
|
2377
|
+
broadcast then reaches every open page that renders it, with no
|
|
2378
|
+
`turbo_stream_from` repeating the key in each view:
|
|
2379
|
+
|
|
2380
|
+
```ruby
|
|
2381
|
+
class Imports::Status < ApplicationComponent
|
|
2382
|
+
include Phlex::Reactive::Component
|
|
2383
|
+
|
|
2384
|
+
reactive_record :import
|
|
2385
|
+
reactive_subscribe :status # the stream [import, :status]
|
|
2386
|
+
# reactive_subscribe key: -> { [@import.account, :imports] } parts, run on the component
|
|
2387
|
+
# reactive_subscribe key: [:lobby, :feed] fixed parts
|
|
2388
|
+
|
|
2389
|
+
def initialize(import:) = @import = import
|
|
2390
|
+
def view_template = div(**reactive_root) { @import.state }
|
|
2391
|
+
end
|
|
2392
|
+
|
|
2393
|
+
# In the job — the key comes from the declaration:
|
|
2394
|
+
Imports::Status.broadcast_self(replace: import) # = broadcast_to(import, :status, replace: import)
|
|
2395
|
+
Imports::Status.broadcast_self(import, js: Phlex::Reactive::JS.new.add_class("#bell", "ring")) # js: names its subject
|
|
2396
|
+
```
|
|
2397
|
+
|
|
2398
|
+
- **The root** carries the stream's signed pgbus src (`data-reactive-subscribe`),
|
|
2399
|
+
the name `broadcast_to(*parts)` publishes to, signed as `pgbus_stream_from`
|
|
2400
|
+
signs it. While the root is on the page, the client's `subscribe` feature keeps
|
|
2401
|
+
one `<pgbus-stream-source>` for it in `<body>`. Roots on the same key share
|
|
2402
|
+
one, a morph or a same-id replace keeps it, a re-keyed root moves to its new
|
|
2403
|
+
stream, and the source sits in a `data-turbo-permanent` box, so a page refresh
|
|
2404
|
+
by morph keeps its connection. The page must load pgbus's
|
|
2405
|
+
client element (`import "pgbus/stream_source_element"`); the doctor looks for
|
|
2406
|
+
that import.
|
|
2407
|
+
- **`broadcast_self`** takes `broadcast_to`'s keywords except `each:`. It reads
|
|
2408
|
+
the key from the component it builds from the payload, or from a subject
|
|
2409
|
+
passed first.
|
|
2410
|
+
- **The actor.** An action on a subscribing root sends that root's own
|
|
2411
|
+
connection id, so `exclude: reactive_connection_id` skips the actor on that
|
|
2412
|
+
stream, but not on another page-level stream.
|
|
2413
|
+
- **Catching up (#478).** On a durable stream (pgbus's
|
|
2414
|
+
`streams_durable_patterns`) the root also carries the stream's watermark at
|
|
2415
|
+
render (`data-reactive-subscribe-since`, read as `pgbus_stream_from` reads it,
|
|
2416
|
+
one query per render), and the source replays from it: a broadcast sent
|
|
2417
|
+
between the render and the connection still arrives, and nothing older does.
|
|
2418
|
+
A source minted again after a page render (a Drive render, a morph that
|
|
2419
|
+
dropped it, every Drive visit of a `data-turbo-permanent` root) opens from
|
|
2420
|
+
its roots' watermarks then: it never skips a frame, but it may replay one a
|
|
2421
|
+
root already shows, so a `js:` or append frame can apply twice.
|
|
2422
|
+
An ephemeral stream (pgbus's default) has nothing to replay. Each time a
|
|
2423
|
+
root's source connects, the root gets `reactive:subscribed`
|
|
2424
|
+
(`detail: { connectionId, reconnect }`, not bubbling), so a component that
|
|
2425
|
+
must not miss a change refetches on it:
|
|
2426
|
+
|
|
2427
|
+
```ruby
|
|
2428
|
+
action :refresh
|
|
2429
|
+
def refresh
|
|
2430
|
+
authorize! @import, :show? # verify_authorized is on by default
|
|
2431
|
+
reply.morph
|
|
2432
|
+
end
|
|
2433
|
+
|
|
2434
|
+
def view_template
|
|
2435
|
+
div(**mix(reactive_root, on(:refresh, event: "reactive:subscribed"))) { @import.state }
|
|
2436
|
+
end
|
|
2437
|
+
```
|
|
2438
|
+
|
|
2439
|
+
A root that joins a source already connected gets no event.
|
|
2440
|
+
- **Refused at render**: a stream name over pgbus's stream-name budget (a
|
|
2441
|
+
UUID-keyed record always is: use `key: -> { [Pgbus.stream_key(@record), :status] }`),
|
|
2442
|
+
a nil record or key part, and any subscribing root on Action Cable, where you
|
|
2443
|
+
render `turbo_stream_from` with the same key instead. A dormant subscribing
|
|
2444
|
+
root is refused when the class loads.
|
|
2445
|
+
|
|
2374
2446
|
### Client-only drafts (`reactive_persist`)
|
|
2375
2447
|
|
|
2376
2448
|
"Don't make me start over": a public application form, a multi-step wizard,
|
|
@@ -29,6 +29,7 @@ registerReactiveFeatureLoader("compute", () => import("phlex/reactive/features/c
|
|
|
29
29
|
registerReactiveFeatureLoader("sortable", () => import("phlex/reactive/features/sortable"))
|
|
30
30
|
registerReactiveFeatureLoader("drag", () => import("phlex/reactive/features/drag"))
|
|
31
31
|
registerReactiveFeatureLoader("presence", () => import("phlex/reactive/features/presence"))
|
|
32
|
+
registerReactiveFeatureLoader("subscribe", () => import("phlex/reactive/features/subscribe"))
|
|
32
33
|
registerReactiveFeatureLoader("countdown", () => import("phlex/reactive/features/countdown"))
|
|
33
34
|
registerReactiveFeatureLoader("effects", () => import("phlex/reactive/features/effects"))
|
|
34
35
|
registerReactiveFeatureLoader("hints", () => import("phlex/reactive/features/hints"))
|