You need to sign in or sign up before continuing.
Commit 3bb9cf01 authored by nanahira's avatar nanahira

fix

parent ab5a0c05
import { Middleware, MiddlewareNext, MiddlewareResult } from './types'; import { Middleware, MiddlewareResult } from './types';
import { AnyClass, ClassType } from '../types'; import { AnyClass, ClassType } from '../types';
import { DynamicMiddlewareDispatcher } from './dynamic-middleware-dispatcher'; import { DynamicMiddlewareDispatcher } from './dynamic-middleware-dispatcher';
...@@ -80,7 +80,7 @@ export class ProtoMiddlewareDispatcher< ...@@ -80,7 +80,7 @@ export class ProtoMiddlewareDispatcher<
for (const cls of chain) { for (const cls of chain) {
const mws = this.middlewareProtoMapPrior.get(cls); const mws = this.middlewareProtoMapPrior.get(cls);
if (mws) { if (mws) {
result.push(...mws); result.push(...[...mws].reverse());
} }
} }
......
...@@ -13,7 +13,15 @@ describe('ProtoMiddlewareDispatcher', () => { ...@@ -13,7 +13,15 @@ describe('ProtoMiddlewareDispatcher', () => {
d.middleware( d.middleware(
Base, Base,
async (x, inst, next) => { async (x, inst, next) => {
order.push('base:prior'); order.push('base:prior1');
return next();
},
true,
);
d.middleware(
Base,
async (x, inst, next) => {
order.push('base:prior2');
return next(); return next();
}, },
true, true,
...@@ -26,6 +34,10 @@ describe('ProtoMiddlewareDispatcher', () => { ...@@ -26,6 +34,10 @@ describe('ProtoMiddlewareDispatcher', () => {
}, },
true, true,
); );
d.middleware(Sub, async (x, inst, next) => {
order.push('sub:normal0');
return next();
});
d.middleware(Sub, async (x, inst, next) => { d.middleware(Sub, async (x, inst, next) => {
order.push('sub:normal'); order.push('sub:normal');
expect(inst).toBeInstanceOf(Sub); expect(inst).toBeInstanceOf(Sub);
...@@ -47,8 +59,10 @@ describe('ProtoMiddlewareDispatcher', () => { ...@@ -47,8 +59,10 @@ describe('ProtoMiddlewareDispatcher', () => {
sub.value = 5; sub.value = 5;
const res = await d.dispatch(3, sub); const res = await d.dispatch(3, sub);
expect(order).toEqual([ expect(order).toEqual([
'base:prior', 'base:prior2',
'base:prior1',
'sub:prior', 'sub:prior',
'sub:normal0',
'sub:normal', 'sub:normal',
'base:normal', 'base:normal',
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment