Skip to content

Commit 0a54b24

Browse files
authored
docs: Improved docs for 2.0 release (#352)
1 parent fb77c00 commit 0a54b24

6 files changed

Lines changed: 125 additions & 49 deletions

File tree

README.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -193,43 +193,6 @@ they will be propagated to all actions and callbacks:
193193

194194
```
195195

196-
## Models
197-
198-
If you need to persist the current state on another object, or you're using the
199-
state machine to control the flow of another object, you can pass this object
200-
to the `StateMachine` constructor:
201-
202-
```py
203-
>>> class MyModel(object):
204-
... def __init__(self, state):
205-
... self.state = state
206-
...
207-
208-
>>> obj = MyModel(state='red')
209-
210-
>>> traffic_light = TrafficLightMachine(obj)
211-
212-
>>> traffic_light.red.is_active
213-
True
214-
215-
>>> obj.state
216-
'red'
217-
218-
>>> obj.state = 'green'
219-
220-
>>> traffic_light.green.is_active
221-
True
222-
223-
>>> traffic_light.slowdown()
224-
225-
>>> obj.state
226-
'yellow'
227-
228-
>>> traffic_light.yellow.is_active
229-
True
230-
231-
```
232-
233196
## A more useful example
234197

235198
A simple didactic state machine for controlling an `Order`:

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ states
1111
transitions
1212
actions
1313
guards
14+
models
1415
observers
1516
mixins
1617
integrations

docs/models.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# Domain models
3+
4+
If you need to use any other object to persist the current state, or you're using the
5+
state machine to control the flow of another object, you can pass this object
6+
to the `StateMachine` constructor.
7+
8+
If you don't pass an explicit model instance, this simple `Model` will be used:
9+
10+
11+
```{literalinclude} ../statemachine/model.py
12+
:language: python
13+
:linenos:
14+
```
15+
16+
```{eval-rst}
17+
.. autoclass:: statemachine.model.Model
18+
:members:
19+
```
20+
21+
```{seealso}
22+
See the {ref}`sphx_glr_auto_examples_order_control_rich_model_machine.py` as example of using a domain object to hold attributes and methods to be used on the `StateMachine` definition.
23+
```
24+
25+
```{hint}
26+
Domain models are registered as {ref}`observers`, so you can have the same level of functionalities provided to the built-in `StateMachine`, such as implementing all callbacks and guards on your domain model and keeping only the definition of states and transitions on
27+
the `StateMachine`.
28+
```

docs/observers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ The `StateMachine` itself is registered as an observer, so by using `.add_observ
4141
external object can have the same level of functionalities provided to the built-in class.
4242
```
4343

44+
```{tip}
45+
{ref}`domain models` are also registered as an observer.
46+
```
47+
48+
4449
```{seealso}
4550
See {ref}`actions`, {ref}`validators and guards` for a list of possible callbacks.
4651

docs/releases/2.0.0.md

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
Welcome to StateMachine 2.0.0!
66

7-
This version is the first to take advantage of the Python3 improvements. We're on our way to implementing features following the SCXML specs. We hope that you enjoy it.
7+
This version is the first to take advantage of the Python3 improvements and is a huge internal refactoring removing the deprecated features on 1.*. We hope that you enjoy it.
88

99
These release notes cover the [](#whats-new-in-20), as well as
1010
some [backwards incompatible changes](#backwards-incompatible-changes-in-20) you'll
11-
want to be aware of when upgrading from StateMachine 1.*. We've
12-
[begun the deprecation process for some features](#deprecated-features-in-20).
11+
want to be aware of when upgrading from StateMachine 1.*.
1312

1413

1514
## Python compatibility in 2.0
@@ -42,12 +41,12 @@ See {ref}`internal transition` for more details.
4241

4342
## Minor features in 2.0
4443

45-
- Modernization of the development stack to use linters.
44+
- Modernization of the development tools to use linters and improved mypy support.
4645
- [#342](https://github.com/fgmacedo/python-statemachine/pull/342): Guards now supports the
47-
evaluation of **truthy**** and **falsy** values.
46+
evaluation of **truthy** and **falsy** values.
4847
- [#342](https://github.com/fgmacedo/python-statemachine/pull/342): Assignment of `Transition`
4948
guards using decorators is now possible.
50-
49+
- [#331](https://github.com/fgmacedo/python-statemachine/pull/331): Added a way to generate diagrams using [QuickChart.io](https://quickchart.io) instead of GraphViz. See {ref}`diagrams` for more details.
5150

5251
## Bugfixes in 2.0
5352

@@ -57,11 +56,91 @@ See {ref}`internal transition` for more details.
5756

5857
## Backward incompatible changes in 2.0
5958

60-
- TODO
61-
### Other backward incompatible changes in 2.0
59+
- Dropped support for Django <= `1.6` for auto-discovering and registering `StateMachine` classes
60+
to be used on {ref}`django integration`.
61+
62+
### Statemachine class changes in 2.0
6263

63-
- TODO
64+
#### `StateMachine.run` removed in favor of `StateMachine.send`
65+
66+
```py
67+
from tests.examples.traffic_light_machine import TrafficLightMachine
68+
69+
sm = TrafficLightMachine()
70+
sm.run("cycle")
71+
72+
```
73+
74+
Should become:
75+
76+
```py
77+
>>> from tests.examples.traffic_light_machine import TrafficLightMachine
78+
79+
>>> sm = TrafficLightMachine()
80+
>>> sm.send("cycle")
81+
'Running cycle from green to yellow'
82+
83+
```
6484

65-
## Deprecated features in 2.0
6685

67-
- TODO
86+
#### `StateMachine.allowed_transitions` removed in favor of `StateMachine.allowed_events`
87+
88+
```py
89+
from tests.examples.traffic_light_machine import TrafficLightMachine
90+
91+
sm = TrafficLightMachine()
92+
assert [t.name for t in sm.allowed_transitions] == ["cycle"]
93+
94+
```
95+
96+
Should become:
97+
98+
```py
99+
>>> from tests.examples.traffic_light_machine import TrafficLightMachine
100+
101+
>>> sm = TrafficLightMachine()
102+
>>> assert [t.name for t in sm.allowed_events] == ["cycle"]
103+
104+
```
105+
106+
#### `Statemachine.is_<state>` removed in favor of `StateMachine.<state>.is_active`
107+
108+
```py
109+
from tests.examples.traffic_light_machine import TrafficLightMachine
110+
111+
sm = TrafficLightMachine()
112+
assert sm.is_green
113+
114+
```
115+
116+
Should become:
117+
118+
```py
119+
>>> from tests.examples.traffic_light_machine import TrafficLightMachine
120+
121+
>>> sm = TrafficLightMachine()
122+
>>> assert sm.green.is_active
123+
124+
```
125+
126+
### State class changes in 2.0
127+
128+
#### `State.identification` removed in favor of `State.id`
129+
130+
```py
131+
from tests.examples.traffic_light_machine import TrafficLightMachine
132+
133+
sm = TrafficLightMachine()
134+
assert sm.current_state.identification == "green"
135+
136+
```
137+
138+
Should become:
139+
140+
```py
141+
>>> from tests.examples.traffic_light_machine import TrafficLightMachine
142+
143+
>>> sm = TrafficLightMachine()
144+
>>> assert sm.current_state.id == "green"
145+
146+
```

docs/releases/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This is the last release series to support Python 2.X series.
3434
3535
```
3636

37-
### 0.* releases
37+
### 0.* release
3838

3939
```{toctree}
4040
:maxdepth: 1

0 commit comments

Comments
 (0)