-
Notifications
You must be signed in to change notification settings - Fork 0
traits.Function.createDebuggableTrait
github-actions[bot] edited this page Jun 8, 2026
·
1 revision
@zenstone/ts-utils / traits / createDebuggableTrait
createDebuggableTrait<
Settings>(config):DebuggableTrait<Settings>
Defined in: src/traits/debuggable.ts:159
创建一个 DebuggableTrait 实现对象,配合 implTraits 混入到目标类。
config 在工厂调用时固定,之后通过原型共享给所有实例(只读)。
运行期的调试开关(debugSettings)通过 setDebug() 写到各实例的自有属性上,
互不干扰。
Settings extends DebugSettings = DebugSettings
Partial<DebugConfiguration>
调试配置(name、color / style、timeFlag 等),详见 DebugConfiguration
DebuggableTrait<Settings>
type AppSettings = DebugSettings & { http?: boolean; ws?: boolean }
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: implTraits guarantees runtime implementation
class AppService {}
implTraits(AppService, createDebuggableTrait<AppSettings>({
name: 'AppService',
color: '#4dabf7', // 仅颜色值,自动包装为 color: #4dabf7
// style: 'color: #4dabf7; font-weight: bold', // 或传完整 CSS
timeFlag: true,
}))
// biome-ignore lint/correctness/noUnusedVariables: trait type extension via implTraits
interface AppService extends DebuggableTrait<AppSettings> {}
const svc = new AppService()
svc.setDebug({ debug: false, http: true })
svc.debug('http', 'request sent', { url: '/api/users' }) // 输出
svc.debug('ws', 'connected') // 静默