MiddlewareContext
The context object passed to middleware execute functions. Provides access to the current state, helper functions, and configuration.
Example
Section titled “Example”const middleware: Middleware = { name: 'validation', execute: (context, next, cancel) => { // Check if any nodes were added if (context.helpers.anyNodesAdded()) { console.log('Nodes added:', context.state.nodes); }
// Access configuration console.log('Cell size:', context.config.background.cellSize);
// Check what action triggered this if (context.modelActionType === 'addNodes') { // Validate new nodes const isValid = validateNodes(context.state.nodes); if (!isValid) { cancel(); // Block the operation return; } }
next(); // Continue to next middleware }};Properties
Section titled “Properties”actionStateManager
Section titled “actionStateManager”actionStateManager:
ActionStateManager
Manager for action states (resizing, linking, etc.)
config
Section titled “config”config:
FlowConfig
The current diagram configuration
edgeRoutingManager
Section titled “edgeRoutingManager”edgeRoutingManager:
EdgeRoutingManager
Manager for edge routing algorithms
edgesMap
Section titled “edgesMap”edgesMap:
Map<string,Edge<object>>
Map for quick edge lookup by ID.
Contains the current state after previous middleware processing.
Use this to access edges by ID instead of iterating through state.edges.
environment
Section titled “environment”environment:
EnvironmentInfo
Environment information (browser, rendering engine, etc.)
helpers
Section titled “helpers”helpers:
MiddlewareHelpers
Helper functions to check what changed (tracks all cumulative changes from the initial action and all previous middlewares)
history
Section titled “history”history:
MiddlewareHistoryUpdate[]
All state updates from previous middlewares in the chain
initialEdgesMap
Section titled “initialEdgesMap”initialEdgesMap:
Map<string,Edge<object>>
The initial edges map before any modifications (before the initial action and before any middleware modifications).
Use this to compare state before and after all modifications.
Common usage: Access removed edge instances that no longer exist in edgesMap.
initialNodesMap
Section titled “initialNodesMap”initialNodesMap:
Map<string,Node>
The initial nodes map before any modifications (before the initial action and before any middleware modifications).
Use this to compare state before and after all modifications.
Common usage: Access removed node instances that no longer exist in nodesMap.
initialState
Section titled “initialState”initialState:
FlowState
The state before any modifications (before the initial action and before any middleware modifications)
initialUpdate
Section titled “initialUpdate”initialUpdate:
FlowStateUpdate
The initial state update that triggered the middleware chain.
Middlewares can add their own updates to the state, so this may not contain all modifications
that will be applied. Use helpers to get actual knowledge about all changes.
modelActionType
Section titled “modelActionType”modelActionType:
ModelActionType
The action that triggered the middleware execution
nodesMap
Section titled “nodesMap”nodesMap:
Map<string,Node>
Map for quick node lookup by ID.
Contains the current state after previous middleware processing.
Use this to access nodes by ID instead of iterating through state.nodes.
state:
FlowState
The current state (includes the initial modification and all changes from previous middlewares)