qor / transition

Transition is a Golang state machine implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GetState() not returning state as expected.

sunwukonga opened this issue · comments

I am playing around trying to add a cart to the qor_example app. When I declare order, I expect to be able to call GetState() as per the documentation.

    order    models.Order

    log.Printf("The initial state of order should be ->draft<-, instead it is ->%v<-", order.GetState())

I can set the state with:

    order.SetState("mystate")

and subsequent calls to GetState() return the string "mystate".

Am I doing something wrong, is the documentation incorrect, or did something break?

I ran go get -u . from the qor/transition directory before posting.

After looking at the code closely, I realized my mistake.

The initialState is a transient state that stands in as a dummy in the first state change and is not initialized until it is in the process of being changed to the first legitimate state (through a call to trigger()). initialState is not a state that can be checked for and reacted to.

The reason that I ran into this at all was because I wanted to use Order as the cart, and stored it in the database. Hence, I would prefer to use a name for the initial state that more obviously reflects its function, like "pre-init". Then use "cart" instead of "checkout", since it is used to hold the cart.