morph "#foo", "Your muscles... they are so tight."
end
end
```
### Nothing morph
Use `morph :nothing` in reflexes that do something on the server without updating the client.
```ruby
# example_reflex.rb
class ExampleReflex <ApplicationReflex
def change
LongRunningJob.perform_later
morph :nothing
end
end
```
## Lifecycle
### Server-side callbacks
Reflex classes can use the following callbacks. [Full Docs](http://docs.stimulusreflex.com/lifecycle#server-side-reflex-callbacks)
-`before_reflex`
-`around_reflex`
-`after_reflex`
### Client-side callbacks (generic)
StimulusReflex controllers automatically support five generic lifecycle callback methods.
-`beforeReflex(element, reflex, noop, reflexId)` prior to sending a request over the web socket
-`reflexSuccess(element, reflex, noop, reflexId)` after the server side Reflex succeeds and the DOM has been updated
-`reflexError(element, reflex, error, reflexId)` whenever the server side Reflex raises an error
-`reflexHalted(element, reflex, noop, reflexId)` reflex canceled with throw :abort in the before_reflex callback
-`afterReflex(element, reflex, noop, reflexId)` after both success and error
-`finalizeReflex(element, reflex, noop, reflexId)` after both success and error
### Client-side callbacks (custom)
StimulusReflex controllers can define up to five custom lifecycle callback methods for each Reflex action. These methods use a naming convention based on the name of the Reflex. e.g. for the `add_one` reflex:
If you need to know when a Reflex method is called, but you're working outside of the Stimulus controller that initiated it, you can subscribe to receive DOM events
-`stimulus-reflex:before`
-`stimulus-reflex:success`
-`stimulus-reflex:error`
-`stimulus-reflex:halted`
-`stimulus-reflex:after`
There are also events related to the StimulusReflex library setting up and connecting to ActionCable
-`stimulus-reflex:connected`
-`stimulus-reflex:disconnected`
-`stimulus-reflex:rejected`
-`stimulus-reflex:ready`
## Helpful tips
### Forms
If a Reflex is called on a form element - or a child of that form element - then the data for the whole form will be properly serialized and made available to the Reflex action method as the `params` accessor. [Read more](http://docs.stimulusreflex.com/working-with-forms)
### Promises
`stimulate()` method returns a promise
```javascript
this.stimulate('Comments#create')
.then(() => this.doSomething())
.catch(() => this.handleError())
```
### Inheriting data-attributes from parent elements
You can use the `data-reflex-dataset="combined"` directive to scoop all data attributes up the DOM hierarchy and pass them as part of the Reflex payload.
Instead of updating your entire page, you can specify exactly which parts of the DOM will be updated using the `data-reflex-root` attribute. [Full docs](http://docs.stimulusreflex.com/morph-modes#scoping-page-morphs)
Add data-reflex-permanent to any element in your DOM, and it will be left unchanged by full-page Reflex updates and morph calls that re-render partials.