From e07f96b65db67e7f08b48ea4b8f5e8ff306053db Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 16 Mar 2022 23:55:07 +0900 Subject: [PATCH] Regular updates --- stimulus-reflex.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/stimulus-reflex.md b/stimulus-reflex.md index a1abdc9..360f296 100644 --- a/stimulus-reflex.md +++ b/stimulus-reflex.md @@ -9,8 +9,9 @@ updated: 2021-01-07 Trigger reflexes without writing any javascript with the `data-reflex` attribute. -```erb - +#### index.html.erb + +```html ``` +#### counter_reflex.rb + ```ruby -# counter_reflex.rb class CounterReflex < StimulusReflex::Reflex def increment @count = element.dataset[:count].to_i + element.dataset[:step].to_i @@ -33,16 +35,18 @@ end Stimulus.js controllers registered with StimulusReflex can use the `stimulate` method to trigger reflexes -```erb - +#### index.html.erb + +```html Increment <%= @count %> ``` +#### counter_controller.js + ```javascript -// counter_controller.js import { Controller } from 'stimulus' import StimulusReflex from 'stimulus_reflex' @@ -58,8 +62,9 @@ export default class extends Controller { } ``` +#### counter_reflex.rb + ```ruby -# counter_reflex.rb class CounterReflex < StimulusReflex::Reflex def increment(step = 1) session[:count] = session[:count].to_i + step @@ -73,14 +78,14 @@ end Instead of refreshing the entire page, you can specify a portion of the page to update with `morph(selector, content)` -```erb +```html
<%= render partial: "path/to/foo", locals: {message: "Am I the medium or the massage?"} %>
``` -```erb +```html
<%= message %> @@ -179,7 +184,7 @@ this.stimulate('Comments#create') 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. -```erb +```html
@@ -188,7 +193,7 @@ You can use the `data-reflex-dataset="combined"` directive to scoop all data att
``` -```ruby +```html # comment_reflex.rb class CommentReflex < ApplicationReflex def create -- 2.11.0