data-reflexattributes. 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_actioncallback 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_reflexwhich 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.
sessionobject will persist across multiple requests; indeed, you can open multiple browser tabs and they will all share the same
session.idvalue on the server. See for yourself: you can create a new session using Incognito Mode or using a 2nd web browser.
session.idto 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..endform of block declaration:
rails dev:cacheon the command line once. Otherwise, if you look in
config/environments/development.rbyou'll see that your cache store will be :null_store, which is exactly as reliable as it sounds.
data-idattributes 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.
redisgem, in tandem with the
hiredisgem 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.