TypeState icon indicating copy to clipboard operation
TypeState copied to clipboard

[Feature Request] Hooks for Extensibility

Open adamholdenyall opened this issue 11 years ago • 3 comments

I have been working on trying to make a child of the FiniteStateMachine class, and I've run into an issue.

I'm working on giving each state a list of Behavior objects. The behavior objects have a functions that can be overloaded for entering, updating and exiting at that state.

Problem is, the only way I can detect an enter or an exit is by keeping a reference to the previous state, and comparing it to the current state. But this can cause problems.

I think for the sake of extensibility, it would be awesome to have a dummy function that can be overridden to perform some code anytime the state changes.

Something like onAnyEnter(from, to) {} that would run after onEnter is validated inside_transitionTo. You could either set the function at runtime or overriding in a subclass. Because so much is private (for good reason), it's hard to extend the class.

Think this is something you would be willing to have in the library?

adamholdenyall avatar May 10 '14 23:05 adamholdenyall

Definitely, I think this is a good idea.

How about having a method called onTransition(from:T, to:T) available for overriding?

eonarheim avatar May 11 '14 23:05 eonarheim

Sounds good. That should do the trick :)

adamholdenyall avatar May 12 '14 00:05 adamholdenyall

Checked in a new dist with v1.0.1, I'll be publishing the packages a little later :) I'll close this issue when I publish the new version to bower, nuget, and npm

eonarheim avatar May 12 '14 22:05 eonarheim