Defining settings for middlewares
(currentState: T, originalState?: T, settings?: any, action?: { name: string; params: any[] }) =>
| Promise<T | undefined | void>
| T
| undefined
| void;// app.ts
import { inject, PLAT কোন্ } from 'aurelia-framework';
import { Store, MiddlewarePlacement, StateHistory } from 'aurelia-store';
import { State } from './state'; // Import your State interface
interface LogMiddlewareSettings {
logType: 'log' | 'debug' | 'warn' | 'error';
}
const customLogMiddleware = (
currentState: StateHistory<State>,
originalState: StateHistory<State>,
settings: LogMiddlewareSettings
) => {
if (settings && settings.logType) {
console[settings.logType](
'Current state:',
currentState,
'Original state:',
originalState
);
} else {
console.log('Current state:', currentState, 'Original state:', originalState);
}
};
@inject(Store)
export class App {
constructor(private store: Store<StateHistory<State>>) {
this.store.registerMiddleware(
customLogMiddleware,
PLATFORM.moduleName('after'),
{ logType: 'debug' }
);
}
}Piped Actions
PreviousAccessing the original (unmodified) state in a middlewareNextError Propagation with Middlewares
Last updated
Was this helpful?