-
Notifications
You must be signed in to change notification settings - Fork 132
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
How to deactive the state machine #31
Comments
@nanatlantica After that you could throw event "switchToTerminateState". - (TKStateMachine *)stateMachine {
return _stateMachine ?: (_stateMachine = [TKStateMachine new], _stateMachine);
}
- (void)activate {
if (self.stateMachine.isActive) {
NSLog(@"%@ %@ stateMachine is active? (%@)", self.debugDescription, NSStringFromSelector(_cmd), self.stateMachine.isActive ? @"YES" : @"NO");
}
else {
// setup machine
[self setupStateMachine:self.stateMachine];
[self.stateMachine activate];
}
}
- (TKStateMachine *)setupStateMachine:(TKStateMachine *)machine {
// for example, you could setup machine here or choose special method for that.
// you need special event that will switch machine to terminate state from ANY state. (except terminate state, of course, it is useless :) )
// you determine states
NSArray *states = @[InitialState, TerminateState, CustomStateOne, CustomStateTwo];
NSArray *statesExceptTerminateState = @[...];
TKEvent *terminatedEvent = [TKEvent eventWithName:[TKStateMachine eventNameTerminated] transitioningFromStates:statesExceptTerminateState toState:terminatedState];
NSArray *events = @[...];
[machine addStates:states];
[machine addEvents:events];
// initial state
machine.initialState = states[0]; // InitialState is first.
return machine;
}
// suppose that you have terminate state.
// event name is eventNameTerminated
- (void)deactivate {
[self.stateMachine fireEvent:[self.stateMachine eventNamed:[TKStateMachine eventNameTerminated]] userInfo:nil error:nil];
self.stateMachine = nil;
}
@interface TKStateMachine (CustomEvents)
+ (NSString *)eventNameTerminated;
@end
|
@lolgear ,Thank you for your answer! And the state machine had worked correctly in my project more than 2 years |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I only found the activate method, can't found the deactivate method
The text was updated successfully, but these errors were encountered: