Any way to add "virtual" i.e. computed state? #182
desmond-dsouza
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Thanks a lot @desmond-dsouza for your feedback and taking time to share your thoughts with us. This idea is gamechanging. I have discussed this topic with @ramedina86 one week ago. This feature would helpful to make development more simple. It was something I would need on some dev because I spend some boilerplate in the backend converted bool to str. The goal is to have states that are updated automatically when other fields are modified. The calculation is done just before sending the messages back to the frontend based on the data that was modified during the request. Syntax proposaldef filter_error(state):
if state['min_length'] < 25:
return 'the filter is disabled because min_length is too low'
if state['min_weight'] > 300:
return 'the filter is disabled because min_weight is too high'
state = initial_state = ss.init_state({
"input": ""
"filter": {
"min_length": 25,
"min_weight": 300,
"filter_disabled": ss.calc_state(['filter.min_length', 'filter.min_weight'], lambda (s): s['min_length'] < 25 or s['min_weight'] > 300) # change when either filter.min_length or filter.min_weight change
"filter_error_message": ss.calc_state(['filter.min_length', 'filter.min_weight'], filter_error)
},
"time": ss.calc_state(lambda s: datetime.now().isoformat()) # change at every event
"input_error": ss.calc_state('input', lambda s: ...) # change when input change
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If I have, say, a computed boolean condition, can the architecture be extended to allow using that boolean condition in the front-end without reifying it into concrete state? Otherwise every computed property has to be explicitly stored & updated, which could become a lot of redundant stored state and code to keep it consistent.
Love the project!
Beta Was this translation helpful? Give feedback.
All reactions