sockpuppet.Reflex. They hold logic responsible for performing operations like writing to your backend data stores. Reflexes are not concerned with rendering because rendering is delegated to the Django view.
sockpuppet.Reflexand lives in your
reflex.py, this is where your Reflex actions are implemented.
stimulatemethod for triggering Reflexes and like all Stimulus controllers, it's aware of the element it is attached to - as well as any Stimulus targets in its DOM hierarchy
data-reflexattribute is placed, which often has data attributes intended to be delivered to the server during a Reflex action
stimulatemethod on your Stimulus controller is being called. We touched on this briefly in the Quick Start chapter; now we are going to document the function signature so that you fully understand what's happening behind the scenes.
StimulusReflex.register(this)called in their
connectmethod gain a
stimulatewith no parameters invokes a special global Reflex that allows you to force a re-render of the current state of your application UI. This is the same thing that the user would see if they hit their browser's Refresh button, except without the painfully slow round-trip cycle.
data-reflexattribute. For example, the following button element will refresh the page content every time the user presses it:
consumer- the Websocket connection from django channels.
request- a django request object
request.post- If the page contains a form, it will find the closest form which and the parameters will be contained here.
session- the Django session store for the current visitor
url- the URL of the page that triggered the reflex
element- an object that represents the HTML element that triggered the reflex
params- Contains the form parameters for the closest form
get_context_data- Accesses the context data from the view associated with the reflex. You will know that the method is triggered from the reflex because the context now contains
stimulus_reflexwhich is equal to
True. This will be available from
kwargsso you can modify the context based on whether it is a reflex or not.
get_channel_id- By default this returns the session key which is used to deliver the websocket update to the client. This function can be overridden if you need a different key for transferring the update.
elementproperty in your Reflexes.
data-reflex-dataset="combined"directive to scoop all data attributes up the hierarchy and pass them as part of the Reflex payload.
data-idwould be 2.