Skip to content

Commit

Permalink
GitBook: [pre-release] 18 pages modified
Browse files Browse the repository at this point in the history
  • Loading branch information
leastbad authored and gitbook-bot committed May 27, 2021
1 parent 51552fd commit f909f45
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Wouldn't it be great if you could **focus on your product** instead of the techn

* [x] Enable small teams to do big things, faster 🏃🏽‍♀️
* [x] Increase developer happiness ❤️❤️❤️
* [x] Facilitate simple, concise, and clear code 🤸
* [x] Facilitate readable, concise, and reusable code 🤸
* [x] Integrate seamlessly with Ruby on Rails 🚝

## New Release: v3.5 - ChillRope Edition
Expand Down
2 changes: 1 addition & 1 deletion docs/appendices/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ Do you have any more weird edge cases? Please let us know!

## Open Issues

There are some things that we'd very much like to fix, but we simply haven't been able to or the responsibility falls to an upstream dependency we don't have direct access to.
There are some things that we'd very much like to fix, but we haven't been able to or the responsibility falls to an upstream dependency we don't have direct access to.

#### iFrame gets refreshed despite data-reflex-permanent

Expand Down
2 changes: 1 addition & 1 deletion docs/rtfm/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ end
### Tokens \(Subscription-based\)

{% hint style="success" %}
You can clone [a simple but fully functioning example application](https://github.com/leastbad/stimulus_reflex_harness/tree/token_auth) based on the Stimulus Reflex Harness. It uses Devise with the `devise-jwt` gem to create a JWT token which is injected into the HEAD. You can use it as a reference for all of the instructions below.
You can clone [a bare bones but fully functioning example application](https://github.com/leastbad/stimulus_reflex_harness/tree/token_auth) based on the Stimulus Reflex Harness. It uses Devise with the `devise-jwt` gem to create a JWT token which is injected into the HEAD. You can use it as a reference for all of the instructions below.
{% endhint %}

There are scenarios where developers might wish to use JWT or some other form of authenticated programmatic access to an application using websockets. For example, you can configure a GraphQL service to accept queries over ActionCable instead of providing an URL endpoint for traditional Ajax calls. You also might need to support multiple custom domains with one ActionCable endpoint. You might also need a solution that doesn't depend on cookies, such as when you want to deploy multiple AnyCable nodes on a service like Heroku.
Expand Down
2 changes: 1 addition & 1 deletion docs/rtfm/cableready.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Do not include `CableReady::Broadcaster` in your Reflex classes. It's already pr

Since StimulusReflex uses CableReady's `morph` and `inner_html` operations, you might be wondering when or if to just use CableReady operations directly instead of calling StimulusReflex's `morph`.

The simple answer is that you should use StimulusReflex when you need life-cycle management; callbacks, events and promises. Reflexes have a transactional life-cycle, where each one is assigned a UUID and the client will have the opportunity to respond if something goes wrong.
The answer is that you should use StimulusReflex when you need life-cycle management; callbacks, events and promises. Reflexes have a transactional life-cycle, where each one is assigned a UUID and the client will have the opportunity to respond if something goes wrong.

CableReady operations raise their own events, but StimulusReflex won't know if they are successful or not. Any CableReady operations you broadcast in a Reflex will be executed immediately.

Expand Down
2 changes: 1 addition & 1 deletion docs/rtfm/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ StimulusReflex controllers automatically support five generic life-cycle callbac
6. `finalizeReflex`

{% hint style="warning" %}
While this is perfect for simpler Reflexes with a small number of actions, most developers quickly switch to using [Custom Life-cycle Methods](lifecycle.md#custom-life-cycle-methods), which allow you to define different callbacks for every action.
While this is perfect for basic Reflexes with a small number of actions, most developers quickly switch to using [Custom Life-cycle Methods](lifecycle.md#custom-life-cycle-methods), which allow you to define different callbacks for every action.
{% endhint %}

In this example, we update each anchor's text before invoking the server side Reflex:
Expand Down
8 changes: 4 additions & 4 deletions docs/rtfm/morph-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Behold! For this is the `foo` partial. It is an example of perfection:
```
{% endcode %}

You create a Selector morph by calling the `morph` method. In its simplest form, it takes two parameters: **selector** and **html**. We pass any valid CSS DOM selector that returns a reference to the first matching element, as well as the value we're updating it with.
You create a Selector morph by calling the `morph` method. Typically, it takes two parameters: **selector** and **html**. We pass any valid CSS DOM selector that returns a reference to the first matching element, as well as the value we're updating it with.

{% code title="app/reflexes/example\_reflex.rb" %}
```ruby
Expand Down Expand Up @@ -249,7 +249,7 @@ That's great - if that's what you want. 🤨
Ultimately, we've optimized for two primary use cases for morph functionality:

1. Updating a partial or ViewComponent to reflect a state change.
2. Updating a container element with a new simple value or HTML fragment.
2. Updating a container element with a new value or HTML fragment.

### Real-world example: Pagy refactoring

Expand Down Expand Up @@ -431,7 +431,7 @@ cable_ready[stream_name].morph({ final update... }).broadcast

### ActiveJob Example

Let's step through creating a simple ActiveJob that will be triggered by a Nothing morph. Upon completion, the job will increment a counter and direct CableReady to update the browser. Note that you'll have to ensure that your ActiveJob infrastructure is up and running, ideally backed by Sidekiq and Redis.
Let's step through creating an ActiveJob that will be triggered by a Nothing morph. Upon completion, the job will increment a counter and direct CableReady to update the browser. Note that you'll have to ensure that your ActiveJob infrastructure is up and running, ideally backed by Sidekiq and Redis.

First, some quick housekeeping: you need to create an ActionCable channel. Running `rails generate channel counter` should do the trick. We want to stream updates to anyone listening in on the `counter` stream.

Expand All @@ -458,7 +458,7 @@ consumer.subscriptions.create("CounterChannel", {
```
{% endcode %}

Create a simple view template that contains a `button` to launch the Reflex as well as a `span` to hold the current value. We'll pull in the current value of the counter key in the Rails cache. If it doesn't yet exist, set the value to 0.
Create a view template that contains a `button` to launch the Reflex as well as a `span` to hold the current value. We'll pull in the current value of the counter key in the Rails cache. If it doesn't yet exist, set the value to 0.

{% code title="index.html.erb" %}
```markup
Expand Down
2 changes: 1 addition & 1 deletion docs/rtfm/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ end

### ViewComponentReflex

We're big fans of using [ViewComponents](https://github.com/github/view_component) in our template rendering process. The [view\_component\_reflex](https://github.com/joshleblanc/view_component_reflex) gem offers a simple mechanism for persistent state in your ViewComponents by automatically storing your component state in the Rails session.
We're big fans of using [ViewComponents](https://github.com/github/view_component) in our template rendering process. The [view\_component\_reflex](https://github.com/joshleblanc/view_component_reflex) gem offers a mechanism for persistent state in your ViewComponents by automatically storing your component state in the Rails session.

Check out the [ViewComponentReflex Expo](http://view-component-reflex-expo.grep.sh/) for inspiration and examples.

Expand Down
4 changes: 2 additions & 2 deletions docs/rtfm/persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We estimate that 80% of the pain points in web development are the direct result
Imagine if you could focus almost all of your time and attention on the fun parts of web development again. Exploring the best way to implement features instead of worrying about data serialization and forgotten user flows. Smaller teams working smarter and faster, then going home on time.

Designing applications in the StimulusReflex mindset is far simpler than what we're used to, and we don't have to give up responsive client functionality to see our productivity shoot through the roof. It does, however, require some unlearning of old habits. You're about to rethink how you approach persisting the state of your application. This can be jarring at first! Even positive changes feel like work.
Designing applications in the StimulusReflex mindset is easier than the request/response we're used to, and we don't have to give up responsive client functionality to see our productivity shoot through the roof. It does, however, require some unlearning of old habits. You're about to rethink how you approach persisting the state of your application. This can be jarring at first! Even positive changes feel like work.

## The life of a Reflex

Expand Down Expand Up @@ -168,7 +168,7 @@ Rails.cache.fetch("preferences:colors:foreground:#{session.id}") {"blue"}

If no key exists, it will evaluate the block, store the value for that key and return the value in one convenient, atomic action. Bam!

If you're planning to do more than set an initial simple value for the fetch default, it's good idiomatic Ruby to move to the `do..end` form of block declaration:
If you're planning to do more than set an initial value for the fetch default, it's good idiomatic Ruby to move to the `do..end` form of block declaration:

{% tabs %}
{% tab title="fortune.html.erb" %}
Expand Down
4 changes: 2 additions & 2 deletions docs/rtfm/working-with-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ params.require(:post).permit(:name, comments_attributes: [:id, :_destroy, :name]

Your `@post` object is instantiated from `params` so if model validations fail, your Post model instance is still in scope when the page re-renders. The model's `errors` collection is available in the view. 🐛

One benefit of this design is that implementing an auto-save feature becomes as simple as adding `data-reflex="change->Post#update"` to each field. Since the field is inside the parent `form` element, all inputs are automatically serialized and sent to your Reflex class.
One benefit of this design is that you can implement an auto-save feature by adding `data-reflex="change->Post#update"` to each field. Since the field is inside the parent `form` element, all inputs are automatically serialized and sent to your Reflex class.

Working with `has_many` associations? No sweat! Building a new record for a nested model requires **no JavaScript**. Your Reflex calls `@post.comments.build` and because Rails knows about the association, any re-renders populate the empty form field as normal.

Expand Down Expand Up @@ -228,7 +228,7 @@ Similarly, custom CableReady operations broadcast by the developer do not automa

## Modifying Forms with Morphs

If you need to change form elements in your document based on user input, you will find yourself needing to re-render partials inside of your Reflex. This raises the very good question of how to access the `form` context, since it's not just a simple view helper that you can include.
If you need to change form elements in your document based on user input, you will find yourself needing to re-render partials inside of your Reflex. This raises the very good question of how to access the `form` context, since it's not just a view helper that you can include.

You will need the controller's view context, as well as the parent resource used to create the form initially:

Expand Down

0 comments on commit f909f45

Please sign in to comment.