From 7a0cf1e8540ae91c339294ad8e6172fa148d3add Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 30 Oct 2024 10:22:24 +0300 Subject: [PATCH] $mol_service refactor detach method, auto init --- offline/install/install.ts | 3 ++- offline/offline.ts | 1 + service/service.ts | 8 ++++++-- service/service.web.ts | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/offline/install/install.ts b/offline/install/install.ts index 59c83e6096..9145751341 100644 --- a/offline/install/install.ts +++ b/offline/install/install.ts @@ -1,3 +1,4 @@ namespace $ { - $mol_service.attach($mol_offline) + // Not needed, just refer to $mol_offline anywhere + // $mol_service.attach($mol_offline) } diff --git a/offline/offline.ts b/offline/offline.ts index 9bcfe626c4..c398dcbcd1 100644 --- a/offline/offline.ts +++ b/offline/offline.ts @@ -65,4 +65,5 @@ namespace $ { } } + $mol_service.attach($mol_offline) } diff --git a/service/service.ts b/service/service.ts index 897a604abe..fd9f421f97 100644 --- a/service/service.ts +++ b/service/service.ts @@ -12,10 +12,13 @@ namespace $ { static attach(plugin: typeof $mol_service_plugin) { this.plugins.add(plugin) - this.init() } - protected static init() {} + static detach(plugin: typeof $mol_service_plugin) { + this.plugins.delete(plugin) + } + + static init() {} static blocked_response() { return new Response( @@ -27,4 +30,5 @@ namespace $ { ) } } + } diff --git a/service/service.web.ts b/service/service.web.ts index 92b2c5cfe9..b23413f477 100644 --- a/service/service.web.ts +++ b/service/service.web.ts @@ -30,7 +30,7 @@ namespace $ { protected static inited = false - protected static override init() { + static override init() { if (this.inited) return if ( this.in_worker() ) { @@ -171,4 +171,6 @@ namespace $ { $.$mol_service = $mol_service_web + $mol_service_web.init() + }