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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25d0d8cfcadeb38db163745b520998196f61fa48865253227abe0e3ee22d5686
4
- data.tar.gz: 7f7f8affa983fa0c0a1543d1118cf67eb3abd609606b1c16fac076b8e5767ad4
3
+ metadata.gz: 467488f15b5926bd5b36c68bf873f04d80a9d1d3196f05b8c610dd7e5bbfed1c
4
+ data.tar.gz: 3d26e273740a16678aea2b6491afe4af7463c7fa492974d2bdccc393787cdb09
5
5
  SHA512:
6
- metadata.gz: 504d3453823e7cf2887da87a0aa9d56839292e2d8fbe2504e7ca76648d0addafef076e2c655eb3d4a1a88d6f688c7709b60237c3c9ed320676dd9fc7a8544a9f
7
- data.tar.gz: aba9941405aea7ca05100162c5f7555c0257a9aee672662614167b30d4d75b3e32dd418f8e24d1ce8d014e2e81c4638d3e7d2ab172714d14cc677b51f3bac3a3
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. No data travels over the WebSocket — your controller stays the single source of truth.
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
  ---
@@ -1,3 +1,3 @@
1
1
  module InertiaCable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cole Robertson