<% end %>
```
### Broadcast Partials Individually
Futurism's default behavior is to `broadcast` partials as they are generated in batches:
On the client side, `IntersectionObserver` events are triggered in a debounced fashion, so several `render`s are performed on the server for each of those events. By default, futurism will group those to a single `broadcast` call (to save server CPU time).
For collections, however, you can opt into individual broadcasts by specifying `broadcast_each: true` in your helper usage:
```erb
<%= futurize @posts, broadcast_each: true, extends: :tr do %>
<% end %>
```
## Events
Once your futurize element has been rendered, the `futurize:appeared` custom event will be called.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'futurism'
```
And then execute:
```bash
$ bundle
```
To copy over the javascript files to your application, run
```bash
$ bin/rails futurism:install
```
**! Note that the installer will run `yarn add @stimulus_reflex/futurism` for you !**
### Manual Installation
After `bundle`, install the Javascript library:
```bash
$ bin/yarn add @stimulus_reflex/futurism
```
In your `app/javascript/channels/index.js`, add the following
```js
import * as Futurism from '@stimulus_reflex/futurism'
import consumer from './consumer'
Futurism.initializeElements()
Futurism.createSubscription(consumer)
```
## Authentication
For authentication, you can rely on ActionCable identifiers, for example, if you use Devise:
```ruby
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = env["warden"].user || reject_unauthorized_connection
end
end
end
```
The [Stimulus Reflex Docs](https://docs.stimulusreflex.com/authentication) have an excellent section about all sorts of authentication.
## Testing
In Rails system tests there is a chance that flaky errors will occur due to Capybara not waiting for the placeholder elements to be replaced. To overcome this, add the flag
```ruby
Futurism.skip_in_test = true
```
to an initializer, for example `config/initializers/futurism.rb`.
## Gotchas
### ActiveStorage URLs aren't correct in development
Out of the box, Rails will prefix generated urls with `http://example.org` rather than `http://localhost`, much like ActionMailer. To amend this, add
```ruby
# config/environments/development.rb
config.action_controller.default_url_options = {host: "localhost", port: 3000}
# config/environments/production.rb
config.action_controller.default_url_options = {host: "mysite.com"}
```
to your environments.
## Contributing
### Get local environment setup
Below are a set of instructions that may help you get a local development environment working
```shell
# Get the gem/npm package source locally
git clone futurism
cd futurism/javascript
yarn install # install all of the npm package's dependencies
yarn link # set the local machine's futurism npm package's lookup to this local path
# Setup a sample project, use the information below directly or use your own project
git clone https://github.com/leastbad/stimulus_reflex_harness.git
cd stimulus_reflex_harness
git checkout futurism
# Edit Gemfile to point point to local gem (e.g. `gem "futurism", path: "../futurism"`)
# yarn link @stimulus_reflex/futurism
# Do your work, Submit PR, Profit!
# To stop using your local version of futurism
# change your Gemfile back to the published (e.g. `gem "futurism"`)
cd path/to/futurism/javascript
# Stop using the local npm package
yarn unlink
# Instruct your project to reinstall the published version of the npm package
cd path/to/project
yarn install --force
```
### Release
1. Update the version numbers in `javascript/package.json` and `lib/futurism/version.rb`
2. `git commit -m "Bump version to x.x.x"`
3. Run `bundle exec rake build`
4. Run `bundle exec rake release`
5. `cd javascript && npm publish --access public`
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!