Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global config, simplify threading, custom operations #96

Merged
merged 12 commits into from
Jan 23, 2021
Merged
150 changes: 78 additions & 72 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,65 @@ PATH
specs:
cable_ready (4.4.6)
rails (>= 5.2)
thread-local (>= 1.1.0)

GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.0)
actionpack (= 6.1.0)
activesupport (= 6.1.0)
actioncable (6.1.1)
actionpack (= 6.1.1)
activesupport (= 6.1.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.0)
actionpack (= 6.1.0)
activejob (= 6.1.0)
activerecord (= 6.1.0)
activestorage (= 6.1.0)
activesupport (= 6.1.0)
actionmailbox (6.1.1)
actionpack (= 6.1.1)
activejob (= 6.1.1)
activerecord (= 6.1.1)
activestorage (= 6.1.1)
activesupport (= 6.1.1)
mail (>= 2.7.1)
actionmailer (6.1.0)
actionpack (= 6.1.0)
actionview (= 6.1.0)
activejob (= 6.1.0)
activesupport (= 6.1.0)
actionmailer (6.1.1)
actionpack (= 6.1.1)
actionview (= 6.1.1)
activejob (= 6.1.1)
activesupport (= 6.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.0)
actionview (= 6.1.0)
activesupport (= 6.1.0)
actionpack (6.1.1)
actionview (= 6.1.1)
activesupport (= 6.1.1)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.0)
actionpack (= 6.1.0)
activerecord (= 6.1.0)
activestorage (= 6.1.0)
activesupport (= 6.1.0)
actiontext (6.1.1)
actionpack (= 6.1.1)
activerecord (= 6.1.1)
activestorage (= 6.1.1)
activesupport (= 6.1.1)
nokogiri (>= 1.8.5)
actionview (6.1.0)
activesupport (= 6.1.0)
actionview (6.1.1)
activesupport (= 6.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.0)
activesupport (= 6.1.0)
activejob (6.1.1)
activesupport (= 6.1.1)
globalid (>= 0.3.6)
activemodel (6.1.0)
activesupport (= 6.1.0)
activerecord (6.1.0)
activemodel (= 6.1.0)
activesupport (= 6.1.0)
activestorage (6.1.0)
actionpack (= 6.1.0)
activejob (= 6.1.0)
activerecord (= 6.1.0)
activesupport (= 6.1.0)
activemodel (6.1.1)
activesupport (= 6.1.1)
activerecord (6.1.1)
activemodel (= 6.1.1)
activesupport (= 6.1.1)
activestorage (6.1.1)
actionpack (= 6.1.1)
activejob (= 6.1.1)
activerecord (= 6.1.1)
activesupport (= 6.1.1)
marcel (~> 0.3.1)
mimemagic (~> 0.3.2)
activesupport (6.1.0)
activesupport (6.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand All @@ -74,11 +75,13 @@ GEM
concurrent-ruby (1.1.7)
crass (1.0.6)
erubi (1.10.0)
faraday (1.1.0)
faraday (1.3.0)
faraday-net_http (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords
faraday-http-cache (2.2.0)
faraday (>= 0.8)
faraday-net_http (1.0.0)
github_changelog_generator (1.15.2)
activesupport
faraday-http-cache
Expand All @@ -89,7 +92,7 @@ GEM
retriable (~> 3.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.5)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
loofah (2.8.0)
crass (~> 1.0.2)
Expand All @@ -102,74 +105,76 @@ GEM
method_source (0.9.2)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.2)
mini_portile2 (2.5.0)
minitest (5.14.3)
multi_json (1.15.0)
multipart-post (2.1.1)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
octokit (4.19.0)
nokogiri (1.11.1)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
octokit (4.20.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.20.1)
parser (2.7.2.0)
parser (3.0.0.0)
ast (~> 2.4.1)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-nav (0.3.0)
pry (>= 0.9.10, < 0.13.0)
public_suffix (4.0.6)
racc (1.5.2)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.0)
actioncable (= 6.1.0)
actionmailbox (= 6.1.0)
actionmailer (= 6.1.0)
actionpack (= 6.1.0)
actiontext (= 6.1.0)
actionview (= 6.1.0)
activejob (= 6.1.0)
activemodel (= 6.1.0)
activerecord (= 6.1.0)
activestorage (= 6.1.0)
activesupport (= 6.1.0)
rails (6.1.1)
actioncable (= 6.1.1)
actionmailbox (= 6.1.1)
actionmailer (= 6.1.1)
actionpack (= 6.1.1)
actiontext (= 6.1.1)
actionview (= 6.1.1)
activejob (= 6.1.1)
activemodel (= 6.1.1)
activerecord (= 6.1.1)
activestorage (= 6.1.1)
activesupport (= 6.1.1)
bundler (>= 1.15.0)
railties (= 6.1.0)
railties (= 6.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.1.0)
actionpack (= 6.1.0)
activesupport (= 6.1.0)
railties (6.1.1)
actionpack (= 6.1.1)
activesupport (= 6.1.1)
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (2.0.0)
rake (13.0.3)
regexp_parser (2.0.3)
retriable (3.1.2)
rexml (3.2.4)
rubocop (1.4.2)
rubocop (1.7.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.1.1)
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.3.0)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
rubocop-performance (1.9.1)
rubocop-performance (1.9.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.10.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.2)
sawyer (0.8.2)
addressable (>= 2.3.5)
Expand All @@ -181,12 +186,13 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
standard (0.10.2)
rubocop (= 1.4.2)
rubocop-performance (= 1.9.1)
standard (0.11.0)
rubocop (= 1.7.0)
rubocop-performance (= 1.9.2)
standardrb (1.0.0)
standard
thor (1.0.1)
thread-local (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
Expand Down
1 change: 1 addition & 0 deletions cable_ready.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
gem.test_files = Dir["test/**/*.rb"]

gem.add_dependency "rails", ">= 5.2"
gem.add_dependency "thread-local", ">= 1.1.0"

gem.add_development_dependency "github_changelog_generator"
gem.add_development_dependency "magic_frozen_string_literal"
Expand Down
4 changes: 4 additions & 0 deletions docs/leveraging-stimulus.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ One question that comes up often on Discord is how to properly handle broadcasts

Our proposed solution is that instead of modifying the DOM directly, send a `dispatch_event` that has the rendered HTML for **both** the current user and everyone else available in _different keys_ of the `detail` object, along with the `user_id` of the contributing user. This `user_id` can be compared against the current user's `id` which has already been stored in a `meta` tag in the document `head`. Upon receiving a new update, the Stimulus controller can append the correct HTML fragment to the correct DOM element and the project is saved.

{% hint style="warning" %}
This technique is not well-suited to scenarios where sensitive data is being transmitted. Since all data being sent is visible via Network Inspector, please assume that all everyone receiving a message can see its contents.
{% endhint %}

#### Example 4: The Stimulus value attribute setter

The recent release of Stimulus v2 finally brought the [Values](https://stimulus.hotwire.dev/reference/values) API. Values maps a data attribute on the DOM element which holds the controller instance to a typed internal value. Updating the data attribute on the DOM element automatically fires a `ValueChanged` callback, if one is available. 👍
Expand Down
18 changes: 16 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ In general, it's easier to track related concepts transactionally in one broadca

CableReady does not \(and could not\) wait for event listeners to finish running before launching the primary function of any particular operation. This means that **if you do something slow in your event handler callback, it will likely finish running** _**after**_ **the operation is completed**. Depending on your expectations, this could cause chaos for inexperienced developers.

##

## Focus assignment

The [DOM Mutation](reference/operations/dom-mutations.md) operations accept an optional `focusSelector` parameter that allows you to specify a CSS selector to which element should be active \(receive focus\) after the operation completes.
Expand Down Expand Up @@ -155,6 +153,22 @@ ActionCable.server.broadcast("users:#{current_user.to_gid_param}", data)

`UsersChannel` becomes `users` while ActiveRecord has a `to_gid_param`.

## Poking a subscriber

Sometimes you just need to tell a subscriber that it's time to _do the thing_. You can send a `broadcast` with no operations and still take advantage of the `received` handler:

```ruby
cable_ready["stream"].broadcast
```

```javascript
consumer.subscriptions.create('ChewiesChannel', {
received (data) {
console.log('Data was received!')
}
})
```

## Disconnect a user from their ActionCable Connection

As you can see in the upcoming section on [connection identifiers](identifiers.md#stream-identifiers-from-accessors), ActionCable Connections can designate that they are able to be `identified_by` one or more objects. These can be strings or ActiveRecord model resources. It is **only** using one of these connection identifiers that you can forcibly disconnect a client connection entirely.
Expand Down
Loading