inertia_cable 0.2.0 → 0.2.1
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/README.md +12 -1
- data/lib/inertia_cable/version.rb +1 -1
- data/lib/inertia_cable.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 467488f15b5926bd5b36c68bf873f04d80a9d1d3196f05b8c610dd7e5bbfed1c
|
|
4
|
+
data.tar.gz: 3d26e273740a16678aea2b6491afe4af7463c7fa492974d2bdccc393787cdb09
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86b16433049aeedf34d478a398531666dec745556bdc21a2090e0d0023658a11aecab505a02ca7727f9e7d60442079a47e009e78cb778c01a37462b862578fc9
|
|
7
|
+
data.tar.gz: 3001e9c9acc8cfaf12d1287caf84700bf43fb4c4a7a28cbec30a9fa4a51ffdb890da1b856859bbe6a73d1ddcf504dd5e9feb23dabda698e61647ad8c5ca46dfc
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
ActionCable broadcast DSL for [Inertia.js](https://inertiajs.com/) Rails applications. Three lines of code to get real-time updates.
|
|
4
4
|
|
|
5
|
-
InertiaCable broadcasts lightweight JSON signals over ActionCable. The client receives them and calls `router.reload()` to re-fetch props through Inertia's normal HTTP flow
|
|
5
|
+
InertiaCable broadcasts lightweight JSON signals over ActionCable. The client receives them and calls `router.reload()` to re-fetch props through Inertia's normal HTTP flow — your controller stays the single source of truth. For ephemeral data like job progress or notifications, [direct messages](#direct-messages) stream data over the WebSocket without triggering a reload.
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
Model save → after_commit → ActionCable broadcast (signal)
|
|
@@ -12,6 +12,8 @@ React hook subscribes → receives signal → router.reload({ only: ['messages']
|
|
|
12
12
|
Inertia HTTP request → controller re-evaluates props → React re-renders
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
> **Coming from Turbo Streams?** `broadcasts_to` replaces `broadcasts_refreshes_to`, and `broadcast_message_to` covers use cases where you'd reach for `broadcast_append_to` or `broadcast_replace_to` — but without HTML partials, since Inertia reloads props from your controller instead.
|
|
16
|
+
|
|
15
17
|
## Table of Contents
|
|
16
18
|
|
|
17
19
|
- [Installation](#installation)
|
|
@@ -381,6 +383,15 @@ useInertiaCable(stream, {
|
|
|
381
383
|
})
|
|
382
384
|
```
|
|
383
385
|
|
|
386
|
+
### Broadcasting without a model instance
|
|
387
|
+
|
|
388
|
+
Use `InertiaCable.broadcast_message_to` from anywhere — jobs, services, controllers — without needing a model instance:
|
|
389
|
+
|
|
390
|
+
```ruby
|
|
391
|
+
InertiaCable.broadcast_message_to("dashboard", data: { alert: "Deployment complete" })
|
|
392
|
+
InertiaCable.broadcast_message_to(user, :notifications, data: { count: 5 })
|
|
393
|
+
```
|
|
394
|
+
|
|
384
395
|
Messages are delivered immediately with no debouncing. Each `broadcast_message_to` call triggers exactly one `onMessage` callback.
|
|
385
396
|
|
|
386
397
|
---
|
data/lib/inertia_cable.rb
CHANGED
|
@@ -28,6 +28,15 @@ module InertiaCable
|
|
|
28
28
|
ActionCable.server.broadcast(resolved, payload)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
# Broadcast a direct message without a model instance.
|
|
32
|
+
#
|
|
33
|
+
# InertiaCable.broadcast_message_to("dashboard", data: { alert: "done" })
|
|
34
|
+
# InertiaCable.broadcast_message_to(user, :notifications, data: { count: 5 })
|
|
35
|
+
#
|
|
36
|
+
def self.broadcast_message_to(*streamables, data:)
|
|
37
|
+
broadcast(streamables, { type: "message", data: data })
|
|
38
|
+
end
|
|
39
|
+
|
|
31
40
|
def self.suppressing_broadcasts(&block)
|
|
32
41
|
InertiaCable::Suppressor.suppressing(&block)
|
|
33
42
|
end
|