// NewStateMachine return a pointer of new StateMachine func NewStateMachine(states ...string) *StateMachine { stateE := make([]gset.Elementer, len(states)) for i, state := range states { stateE[i] = gset.T(state) } stateSet := gset.NewSet(stateE...) return &StateMachine{make(map[string]*Event), stateSet} }
// Transition add transition for this event, error will not be nil // if any state in to or froms does not exit func (e *Event) Transition(to string, froms ...string) error { states := append(froms[:], to) for _, state := range states { if !e.sm.states.Has(gset.T(state)) { return fmt.Errorf("has not state: %s", state) } } e.to = to e.froms = froms return nil }
// Delete deletes the LineItem and its related data with the given id func (model *Model) Delete(id float64) { model.Lock() defer model.Unlock() li, ok := model.Get(id) if !ok { return } li.DeleteRelatedLis(id, model) model.Set.Remove(gset.T(id)) model.dataChanged = true model.removeUniqueValues(li) }
// Has returns if Model has LineItem with the given id func (model *Model) Has(id float64) bool { return model.Set.Has(gset.T(id)) }