Skip to content

Commit

Permalink
feat: trigger a calculated property on mutation
Browse files Browse the repository at this point in the history
* docs: improve the documentation of application state
  • Loading branch information
FabienArcellier committed Aug 1, 2024
1 parent 39a98b0 commit 9465a76
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/framework/application-state.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,33 @@ The front-end cannot directly display complex data types such as Pandas datafram
Pandas dataframes are converted to JSON and can be used in _Dataframe_ components.
</Tab>
</Tabs>

## State schema

State schema is a feature that allows you to define the structure of the state.
This is useful for ensuring that the state is always in the expected format.

Schema allows you to use features like

* typing checking with mypy / ruff
* autocomplete in IDEs
* declare dictionaries
* automatically calculate mutations on properties

more into [Advanced > State schema](./state-schema)

```python
import writer as wf

class AppSchema(wf.WriterState):
counter: int

initial_state = wf.init_state({
"counter": 0
}, schema=AppSchema)

# Event handler
# It receives the session state as an argument and mutates it
def increment(state: AppSchema):
state.counter += 1
```

0 comments on commit 9465a76

Please sign in to comment.