Пример #1
0
// 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}
}
Пример #2
0
// 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
}
Пример #3
0
// 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)
}
Пример #4
0
// Has returns if Model has LineItem with the given id
func (model *Model) Has(id float64) bool {
	return model.Set.Has(gset.T(id))
}