You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Middlewares trigger exclusively on events that are explicitly attached. If a variable is bound, they are not triggered. It's not practical.
Here is the example of a weather station where I would like to write a file with the state each time a variable changes. I have to explicitly attach an event handler for the middleware mechanism to work.
importioimportjsonimportwriteraswf@wf.middleware()defon_change(state: wf.WriterState):
yieldwithio.open("weather.json", "w") asf:
f.write(json.dumps(state.to_dict()))
# I have to attach this event handler. # I would prefer to trigger on any eventdefon_trigger():
passinitial_state=wf.init_state({
"outside_atmospheric_pressure_now": 1026.0,
"outside_humidity": 0,
"outside_wind_speed": 0,
"outside_temperature": 22
})
Middlewares trigger exclusively on events that are explicitly attached. If a variable is bound, they are not triggered. It's not practical.
Here is the example of a weather station where I would like to write a file with the state each time a variable changes. I have to explicitly attach an event handler for the middleware mechanism to work.
The text was updated successfully, but these errors were encountered: