From 51dafe0f9ad9c759c3284e07f6e8f0428f450716 Mon Sep 17 00:00:00 2001 From: xion Date: Wed, 14 May 2025 21:12:08 +0800 Subject: [PATCH] perf --- src/router-define.ts | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/router-define.ts b/src/router-define.ts index 55a17e2..af8f294 100644 --- a/src/router-define.ts +++ b/src/router-define.ts @@ -70,6 +70,18 @@ class Chain { return this; } } +class QueryChain { + obj: SimpleObject = {}; + constructor(value?: SimpleObject, opts?: SimpleObject) { + this.obj = value || {}; + } + get(queryData?: Record): Pick { + return { + ...this.obj, + ...queryData, + }; + } +} export const util = { getChain: (obj: RouteOpts, opts?: ChainOptions) => { return new Chain(obj, opts); @@ -77,10 +89,10 @@ export const util = { }; export class QueryUtil { - routeObject: T; + obj: T; app: QueryRouterServer; constructor(object: T, opts?: ChainOptions) { - this.routeObject = object; + this.obj = object; this.app = opts?.app; } static createFormObj(object: U, opts?: ChainOptions) { @@ -91,20 +103,18 @@ export class QueryUtil { return new QueryUtil(obj, opts); } get(key: K): RouteOpts { - return this.routeObject[key] as RouteOpts; + return this.obj[key] as RouteOpts; } chain(key: K, opts?: ChainOptions) { - const obj = this.routeObject[key]; + const obj = this.obj[key]; let newOpts = { app: this.app, ...opts }; return new Chain(obj, newOpts); } - queryChain(key: K): (queryData?: Record) => RouteOpts { - const value = this.routeObject[key]; - return (queryData?: Record) => { - return { - ...value, - ...queryData, - }; - }; + queryChain(key: K) { + const value = this.obj[key]; + return new QueryChain(value); + } + get routeObject() { + return this.obj; } }