refactor(client): shared declaration-aware registration deferral
The five settings-surface registrants carried near-identical spec-check/ledger-judge/subscribe scaffolding (three jscpd clones); ui-slots now owns deferRegistration() — ledger-judged presence, refresh for registrant-localized labels, one-call disposal — and every registrant shrinks to its registration body.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* discipline: packages/client/AGENTS.md.
|
||||
*/
|
||||
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { deferRegistration } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
// Type-only: pulls the shell's SlotMap merge (the 'settings.section' entry).
|
||||
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
||||
// Type-only: pulls the locale plugin's Context merge (ctx.locale).
|
||||
@@ -31,37 +32,20 @@ export function apply(ctx: ClientContext): void {
|
||||
]
|
||||
return () => { for (const dispose of disposers) dispose() }
|
||||
}, 'ui-models: nav copy dictionaries')
|
||||
// Declaration-aware registration; the LEDGER is the has-registered judge
|
||||
// (not a local flag): after an HMR collapse re-declares the slot, the
|
||||
// cascade already removed our entry, and a stale disposer must not block
|
||||
// the re-registration.
|
||||
ctx.effect(() => {
|
||||
let dispose: (() => void) | undefined
|
||||
const tryRegister = (): void => {
|
||||
if (ctx.slots.spec('settings.section') === undefined) return
|
||||
if (ctx.slots.entries('settings.section').some(e => e.component === ModelsSection)) return
|
||||
dispose = ctx.slots.register({
|
||||
const deferred = deferRegistration(ctx.slots, 'settings.section', ModelsSection, () =>
|
||||
ctx.slots.register({
|
||||
name: 'settings.section',
|
||||
id: 'models',
|
||||
order: 10,
|
||||
label: ctx.locale.bind('settings.models')('nav'),
|
||||
}, ModelsSection)
|
||||
}
|
||||
// Nav labels are registrant-localized: re-register on locale change so
|
||||
// the ledger carries fresh text (the version bump re-renders the shell).
|
||||
// Dispose-then-requery: after an HMR collapse the disposer is stale and
|
||||
// the ledger/spec re-check keeps this path an idempotent no-op.
|
||||
const offLocale = ctx.on('locale/change', () => {
|
||||
dispose?.()
|
||||
dispose = undefined
|
||||
tryRegister()
|
||||
})
|
||||
const unsubscribe = ctx.slots.subscribe('settings.section', () => { tryRegister() })
|
||||
tryRegister()
|
||||
}, ModelsSection))
|
||||
// Nav labels are registrant-localized: refresh on locale change so the
|
||||
// ledger carries fresh text (the version bump re-renders the shell).
|
||||
const offLocale = ctx.on('locale/change', () => { deferred.refresh() })
|
||||
return () => {
|
||||
offLocale()
|
||||
unsubscribe()
|
||||
dispose?.()
|
||||
deferred.dispose()
|
||||
}
|
||||
}, 'ui-models: settings section registration')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user