Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermitIf error message #28

Open
PaulVipond opened this issue Oct 1, 2016 · 2 comments
Open

PermitIf error message #28

PaulVipond opened this issue Oct 1, 2016 · 2 comments
Labels

Comments

@PaulVipond
Copy link

PaulVipond commented Oct 1, 2016

Hi Prasanna,

I'm getting the following error message from my _machineConfig.ForState() statement below when I run it:

"Permit* and Ignore* methods are exclusive to each other for a given resulting state."

I'm not quite sure how to interpret it. Does this mean that you can't have multiple PermitIf statements referring to the same parameterized trigger for the same state? In the example below, I'm reusing the same parameterized trigger using guard clauses to get from one state to 3 different states.

If you have the time, I'd appreciate some examples for PermitIf in the readme / sample to clarify thanks.

        private AwaitableConfiguration<AccountStateType, AccountStateTrigger> _machineConfig;

        private ParameterizedTrigger<AccountStateTrigger, RegistrationRequest> _registrationTrigger;

        public AccountStateMachine()
        {
            _machineConfig = StateMachineFactory.CreateAwaitableConfiguration<AccountStateType, AccountStateTrigger>();

            _registrationTrigger = _machineConfig.SetTriggerParameter<RegistrationRequest>(AccountStateTrigger.RegisterAccount);

            _machineConfig.ForState(AccountStateType.Unregistered)
                .PermitIf(async () => await stateCheck_registrationsSuspended(), _registrationTrigger, AccountStateType.AwaitingSiteRegistrationsTurnedOn, async request => await stateFired_AwaitingSiteRegistrationsTurnedOn(request))
                .PermitIf(async () => !(await stateCheck_registrationsSuspended()) && await stateCheck_paidRegistrations(), _registrationTrigger, AccountStateType.AwaitingPayment, async request => await stateFired_AwaitingPayment(request))
                .PermitIf(async () => !(await stateCheck_registrationsSuspended()) && !(await stateCheck_paidRegistrations()), _registrationTrigger, AccountStateType.AwaitingVerification, async request => await stateFired_AwaitingVerification_viaRegistration(request));
...
@prasannavl
Copy link
Owner

prasannavl commented Oct 2, 2016

Hello.

Sorry for the delay. Been offline briefly. And you're right - A single trigger can only be associated with one resulting state, and used once.

https://github.com/prasannavl/LiquidState/blob/master/LiquidState/Synchronous/Core/StateConfigurationMethodHelper.cs#L83 - That's what prevents it. Have a look at the representations to get an idea of why it is done the way it is.

Simply put, PermitIf helpers are for very simple scenarios with a single condition for a single resulting state for a trigger. Its so that the configuration code is readable and simple. Thinks of triggers are your entry knobs for a sequence of actions. You turn a knob, and that knob has only one travel direction. Nothing more, nothing less. So, here you're providing the same knob, and providing three different conditions, and asking it to move in three different directions.

If that's how you'd like to approach it, use PermitDynamic. That should bypass all of this, and allow you to take complete control and move in whichever direction you want based on whatever condition . Use that and take and isolate the trigger's conditional mechanisms out of the state machine.

However, your right about the error message not being very helpful here. I will try to rectify that soon.

@PaulVipond
Copy link
Author

Thanks for the explanation Prasanna. I will take a look at PermitDynamic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants