inertia_cable 0.2.1 → 0.2.2

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: 467488f15b5926bd5b36c68bf873f04d80a9d1d3196f05b8c610dd7e5bbfed1c
4
- data.tar.gz: 3d26e273740a16678aea2b6491afe4af7463c7fa492974d2bdccc393787cdb09
3
+ metadata.gz: 77598665249ec9fc7f6d8fa69ad070661e2db15513a1720c83e937e318e4b828
4
+ data.tar.gz: 388cc18e32909027f18da2b65352859299120f18984e2a1e7f15fc1e3fff905a
5
5
  SHA512:
6
- metadata.gz: 86b16433049aeedf34d478a398531666dec745556bdc21a2090e0d0023658a11aecab505a02ca7727f9e7d60442079a47e009e78cb778c01a37462b862578fc9
7
- data.tar.gz: 3001e9c9acc8cfaf12d1287caf84700bf43fb4c4a7a28cbec30a9fa4a51ffdb890da1b856859bbe6a73d1ddcf504dd5e9feb23dabda698e61647ad8c5ca46dfc
6
+ metadata.gz: 4b9ae8be00c92656c2ce2787e2ec939028a3cebc77cb7c54adbc2acf4c673cebea5e828fae83e3e8f76bef7ee7c10e266de0eea3cdcce5ba3a3180f2705586ef
7
+ data.tar.gz: 16182946b7e2f836b14aed916c937762002052c8cab9c48617d47eb3599b42e4fcb35b307a1c7c93c59f1e3a08c5f8ef979b09db46a4431a365647a252d6a4b8
data/README.md CHANGED
@@ -418,13 +418,24 @@ end
418
418
 
419
419
  Optionally coalesce rapid broadcasts using Rails cache. **Not used by default** — the client-side 100ms debounce handles most cases.
420
420
 
421
- Requires a shared cache store (Redis, Memcached, or SolidCache) in multi-process deployments.
421
+ Server-side debounce is useful when a single operation triggers many model callbacks (e.g., bulk imports, cascading updates) and you want to reduce the number of ActionCable messages sent. The client-side debounce already coalesces rapid reloads into one, so server-side debounce is only needed when the volume of WebSocket messages itself is a concern.
422
+
423
+ Requires a shared cache store (Redis, Memcached, or SolidCache) in multi-process deployments. `MemoryStore` (the Rails default) only works within a single process.
422
424
 
423
425
  ```ruby
424
- InertiaCable.debounce_delay = 0.5 # seconds (default)
426
+ # Via the model DSL
427
+ broadcasts_to :board, debounce: true # uses InertiaCable.debounce_delay (0.5s)
428
+ broadcasts_to :board, debounce: 1.0 # custom delay in seconds
429
+
430
+ # Via instance methods
431
+ post.broadcast_refresh_later_to(board, debounce: 2.0)
425
432
 
433
+ # Direct usage
426
434
  InertiaCable::Debounce.broadcast("my_stream", payload)
427
435
  InertiaCable::Debounce.broadcast("my_stream", payload, delay: 2.0)
436
+
437
+ # Configure the global default
438
+ InertiaCable.debounce_delay = 0.5 # seconds (default)
428
439
  ```
429
440
 
430
441
  ---
@@ -475,6 +486,21 @@ end
475
486
 
476
487
  All three accept splat streamables: `assert_broadcasts_on(chat, :messages) { ... }`
477
488
 
489
+ ### Broadcast callbacks
490
+
491
+ `InertiaCable.on_broadcast` registers a callback that fires for every broadcast (including debounced ones). The test helpers use this internally, but you can use it for custom instrumentation or logging:
492
+
493
+ ```ruby
494
+ callback = ->(stream_name, payload) {
495
+ Rails.logger.info "[InertiaCable] #{payload[:type]} on #{stream_name}"
496
+ }
497
+
498
+ InertiaCable.on_broadcast(&callback)
499
+
500
+ # Later, to unregister:
501
+ InertiaCable.off_broadcast(&callback)
502
+ ```
503
+
478
504
  ---
479
505
 
480
506
  ## Configuration
@@ -6,6 +6,7 @@ module InertiaCable
6
6
  return if Rails.cache.exist?(cache_key)
7
7
 
8
8
  Rails.cache.write(cache_key, true, expires_in: delay)
9
+ InertiaCable.broadcast_callbacks.each { |cb| cb.call(stream_name, payload) }
9
10
  ActionCable.server.broadcast(stream_name, payload)
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaCable
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cole Robertson