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 +4 -4
- data/README.md +28 -2
- data/lib/inertia_cable/debounce.rb +1 -0
- data/lib/inertia_cable/version.rb +1 -1
- 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: 77598665249ec9fc7f6d8fa69ad070661e2db15513a1720c83e937e318e4b828
|
|
4
|
+
data.tar.gz: 388cc18e32909027f18da2b65352859299120f18984e2a1e7f15fc1e3fff905a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|