state-machine
state-machine copied to clipboard
Additional data can be used when getting the state for a transition
Hi there,
First of all props for the amazing library! It works perfectly with states as string. But in my use case, I would like to store some additional data alongside the state of the object like the datetime of when the object has transitioned to state.
To store such information, I made the state an entity instead of a string. And by overriding the new getStateForTransition
method in my own StateMachine class, I can return an object instead of a string. To add data to the state object, you can pass an additional array.
Hopefully you'll like the idea :-) otherwise you have some thoughts how I can resolve this with your library.
Hi,
Sorry for not having reviewedd this earlier, I totally missed it.
Unfortunately this is quite a big BC break so I can't merge it like this. If you're using Symfony you can call services as callbacks, in which you can access any additional data, could it be a solution for you?
Thanks
I think adding this feature (with more test and a documentation) will make this lib way better than yohang/Finite.
winzou/state-machine can handle multiple graph with multiple state in a single object, yohang/Finite can't. But yohang/Finite can have context with state and transition with is very useful. see http://finite.readthedocs.org/en/master/examples/transition-properties.html
If you want I am available to help you to achieve this.
What do you think @winzou @robinvdvleuten ?