Skip to content

Add Middleware for Pre-Transition Validation (fluentState.use()) #68

@JasonPierce

Description

@JasonPierce

Fluent-State lacks a way to intercept and modify state transitions before they occur. Adding fluentState.use((prev, next, transition) => {...}) allows developers to implement logging, security checks, or validation before proceeding.

Example Usage:

fluentState.use((prev, next, transition) => {
  console.log(`Checking transition: ${prev}${next}`);

  if (next === 'mainApp' && !userHasAccess()) {
    console.log("Access Denied!");
    return; // Prevents transition
  }

  transition(); // Proceed to next state
});

Acceptance Criteria (AC):

  • Middleware should run before transitioning to the next state.
  • If transition() is not called, the transition should be blocked.
  • Multiple middleware functions should execute in order.
  • Existing unit tests pass.
  • Add new unit tests for all AC.
  • Test cases should include middleware execution and blocking transitions.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions