From harness-claude
Implements JavaScript State pattern to encapsulate state-dependent behavior and transitions. Replaces complex conditionals for workflows, UI state machines, or protocol handlers with 3+ states.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Allow an object to alter its behavior when its internal state changes
Implements GOF State Pattern to replace if/else chains with state objects delegating behavior by current state. For state machines like order lifecycles, connections, vending machines.
Generates State pattern for PHP 8.4 including context, state interface, concrete states, factory, entity updates, exceptions, and unit tests for state-dependent object behavior like order workflows.
Models complex UI flows as finite state machines with states, events, transitions, actions, and guards. Useful for forms, data fetching, authentication flows, and wizards.
Share bugs, ideas, or general feedback.
Allow an object to alter its behavior when its internal state changes
context.setState(newState).class TrafficLight {
constructor() {
this.state = new RedState(this);
}
setState(state) {
this.state = state;
}
signal() {
this.state.signal();
}
}
class RedState {
constructor(light) {
this.light = light;
}
signal() {
console.log('Red — stop');
this.light.setState(new GreenState(this.light));
}
}
class GreenState {
constructor(light) {
this.light = light;
}
signal() {
console.log('Green — go');
this.light.setState(new RedState(this.light));
}
}
const light = new TrafficLight();
light.signal(); // Red — stop
light.signal(); // Green — go
The State pattern encapsulates state-dependent behavior into separate classes. The context object delegates to the current state, and states handle transitions. This eliminates complex conditionals and makes adding new states straightforward.
Trade-offs:
When NOT to use:
https://patterns.dev/javascript/state-pattern