* This is at least 98% true.
data-reflex
attributes. Those attributes become event handlers that map to methods in Stimulus controllers. The controllers connect events in your browser to methods in your Reflex classes on the server.before_action
callback that fires before the controller even kicks in.||=
(pronounced "or equals") operator helps us manage this hand-off:||=
will only set the instance variable to be 0 if there hasn't already been a value set in the Reflex method.@stimulus_reflex
which is set to true
. You can use this variable to create an if/else block in your controller that behaves differently depending on whether it's being called within the context of a Reflex update or not.session[:balls_left]
will be set to 3 before the initial HTML page has been rendered and transmitted.session
object will persist across multiple requests; indeed, you can open multiple browser tabs and they will all share the same session.id
value on the server. See for yourself: you can create a new session using Incognito Mode or using a 2nd web browser.ActiveSupport::Cache
which provides the underlying infrastructure for Russian doll caching. It can be called directly and that it has a solid offering of utility methods such as increment
and decrement
for numeric values.session.id
to help us build a unique key string to look up the current value. The structure of the key is free-form, but the convention is to use colon characters to build up a namespace, terminating in a unique identifier. For example:do..end
form of block declaration:rails dev:cache
on the command line once. Otherwise, if you look in config/environments/development.rb
you'll see that your cache store will be :null_store, which is exactly as reliable as it sounds.session.id
, the data-id
attributes from individual Todo model instances, and the new Rails &
safe navigation operator (available since Ruby 2.3) to make short work of mapping events on the client to your permanent data store.redis
gem, in tandem with the hiredis
gem for optimal performance) from your Reflex methods allows you to work with the full suite of data structure manipulation tools that are available in response to the state change operations your users initiate.