Skip to content

Commit 7eee200

Browse files
committed
better unloading message
1 parent e75f61d commit 7eee200

File tree

9 files changed

+52
-18
lines changed

9 files changed

+52
-18
lines changed

src/renderChildren/ButtonMDRC.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { RenderChildType } from '../config/FieldConfigs';
44
import type MetaBindPlugin from '../main';
55
import ErrorIndicatorComponent from '../utils/errors/ErrorIndicatorComponent.svelte';
66
import { ButtonField } from '../fields/button/ButtonField';
7+
import { showUnloadedMessage } from '../utils/Utils';
78

89
export class ButtonMDRC extends AbstractMDRC {
910
content: string;
@@ -41,10 +42,10 @@ export class ButtonMDRC extends AbstractMDRC {
4142
public onunload(): void {
4243
console.log('meta-bind | ButtonMDRC >> onunload');
4344
this.buttonField?.unmount();
44-
this.containerEl.empty();
45-
this.containerEl.className = '';
46-
this.containerEl.addClass('mb-error');
47-
this.containerEl.innerText = 'unloaded meta bind button';
4845
this.plugin.mdrcManager.unregisterMDRC(this);
46+
47+
showUnloadedMessage(this.containerEl, 'button');
48+
49+
super.onunload();
4950
}
5051
}

src/renderChildren/EmbedMDRC.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MarkdownRenderer } from 'obsidian';
44
import { MDLinkParser } from '../parsers/MarkdownLinkParser';
55
import { ErrorLevel, MetaBindEmbedError } from '../utils/errors/MetaBindErrors';
66
import { RenderChildType } from '../config/FieldConfigs';
7+
import { showUnloadedMessage } from '../utils/Utils';
78

89
export const EMBED_MAX_DEPTH = 8;
910

@@ -63,6 +64,8 @@ export class EmbedMDRC extends AbstractMDRC {
6364
}
6465

6566
public async onload(): Promise<void> {
67+
console.log('meta-bind | EmbedMDRC >> unload', this);
68+
6669
this.plugin.mdrcManager.registerMDRC(this);
6770

6871
if (this.depth >= EMBED_MAX_DEPTH) {
@@ -77,6 +80,12 @@ export class EmbedMDRC extends AbstractMDRC {
7780
}
7881

7982
public onunload(): void {
83+
console.log('meta-bind | EmbedMDRC >> unload', this);
84+
8085
this.plugin.mdrcManager.unregisterMDRC(this);
86+
87+
showUnloadedMessage(this.containerEl, 'embed');
88+
89+
super.onunload();
8190
}
8291
}

src/renderChildren/ExcludedMDRC.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export class ExcludedMDRC extends AbstractMDRC {
1515

1616
public onunload(): void {
1717
console.log('meta-bind | ExcludedMDRC >> unload', this);
18+
1819
this.plugin.mdrcManager.unregisterMDRC(this);
20+
21+
super.onunload();
1922
}
2023
}

src/renderChildren/InlineButtonMDRC.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type MetaBindPlugin from '../main';
33
import { RenderChildType } from '../config/FieldConfigs';
44
import ErrorIndicatorComponent from '../utils/errors/ErrorIndicatorComponent.svelte';
55
import { InlineButtonField } from '../fields/button/InlineButtonField';
6+
import { showUnloadedMessage } from '../utils/Utils';
67

78
export class InlineButtonMDRC extends AbstractMDRC {
89
content: string;
@@ -37,11 +38,12 @@ export class InlineButtonMDRC extends AbstractMDRC {
3738

3839
public onunload(): void {
3940
console.log('meta-bind | InlineButtonMDRC >> onunload');
41+
4042
this.buttonField?.unmount();
41-
this.containerEl.empty();
42-
this.containerEl.className = '';
43-
this.containerEl.addClass('mb-error');
44-
this.containerEl.innerText = 'unloaded meta bind button';
4543
this.plugin.mdrcManager.unregisterMDRC(this);
44+
45+
showUnloadedMessage(this.containerEl, 'inline button');
46+
47+
super.onunload();
4648
}
4749
}

src/renderChildren/InputFieldMDRC.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type ClassInputFieldArgument } from '../fields/fieldArguments/inputFiel
22
import { ErrorLevel, MetaBindInternalError } from '../utils/errors/MetaBindErrors';
33
import { type ShowcaseInputFieldArgument } from '../fields/fieldArguments/inputFieldArguments/arguments/ShowcaseInputFieldArgument';
44
import { type TitleInputFieldArgument } from '../fields/fieldArguments/inputFieldArguments/arguments/TitleInputFieldArgument';
5-
import { isTruthy } from '../utils/Utils';
5+
import { isTruthy, showUnloadedMessage } from '../utils/Utils';
66
import { AbstractMDRC } from './AbstractMDRC';
77
import type MetaBindPlugin from '../main';
88
import ErrorIndicatorComponent from '../utils/errors/ErrorIndicatorComponent.svelte';
@@ -144,7 +144,7 @@ export class InputFieldMDRC extends AbstractMDRC implements IInputFieldBase {
144144
}
145145

146146
onload(): void {
147-
console.log('meta-bind | InputFieldMarkdownRenderChild >> load', this);
147+
console.log('meta-bind | InputFieldMDRC >> load', this);
148148

149149
this.containerEl.addClass('mb-input');
150150
this.containerEl.empty();
@@ -189,13 +189,12 @@ export class InputFieldMDRC extends AbstractMDRC implements IInputFieldBase {
189189
}
190190

191191
onunload(): void {
192-
console.log('meta-bind | InputFieldMarkdownRenderChild >> unload', this);
192+
console.log('meta-bind | InputFieldMDRC >> unload', this);
193193

194194
this.inputField?.destroy();
195195
this.plugin.mdrcManager.unregisterMDRC(this);
196196

197-
this.containerEl.empty();
198-
this.containerEl.createEl('span', { text: 'unloaded meta bind input field', cls: 'mb-error' });
197+
showUnloadedMessage(this.containerEl, 'input field');
199198

200199
super.onunload();
201200
}

src/renderChildren/JsViewFieldMDRC.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type ComputedMetadataSubscription,
1010
type ComputedSubscriptionDependency,
1111
} from '../metadata/ComputedMetadataSubscription';
12-
import { getUUID } from '../utils/Utils';
12+
import { getUUID, showUnloadedMessage } from '../utils/Utils';
1313
import { type TFile } from 'obsidian';
1414
import { type JsExecution } from 'jsEngine/engine/JsExecution';
1515
import { type RenderChildType } from '../config/FieldConfigs';
@@ -185,8 +185,7 @@ export class JsViewFieldMDRC extends AbstractViewFieldMDRC {
185185
this.plugin.mdrcManager.unregisterMDRC(this);
186186
this.unregisterSelfFromMetadataManager();
187187

188-
this.containerEl.empty();
189-
this.containerEl.createEl('span', { text: 'unloaded meta bind view field', cls: 'mb-error' });
188+
showUnloadedMessage(this.containerEl, 'js view field');
190189

191190
super.onunload();
192191
}

src/renderChildren/ViewFieldMDRC.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type ViewFieldArgumentMapType } from '../fields/fieldArguments/viewFiel
99
import { RenderChildType, type ViewFieldArgumentType } from '../config/FieldConfigs';
1010
import { type BindTargetDeclaration } from '../parsers/bindTargetParser/BindTargetDeclaration';
1111
import { type IViewFieldBase } from '../fields/viewFields/IViewFieldBase';
12+
import { showUnloadedMessage } from '../utils/Utils';
1213

1314
export interface ViewFieldVariable {
1415
bindTargetDeclaration: BindTargetDeclaration;
@@ -144,8 +145,7 @@ export class ViewFieldMDRC extends AbstractViewFieldMDRC implements IViewFieldBa
144145
this.viewField?.destroy();
145146
this.plugin.mdrcManager.unregisterMDRC(this);
146147

147-
this.containerEl.empty();
148-
this.containerEl.createEl('span', { text: 'unloaded meta bind view field', cls: 'mb-error' });
148+
showUnloadedMessage(this.containerEl, 'view field');
149149

150150
super.onunload();
151151
}

src/utils/Utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,14 @@ export function toEnumeration(
194194
export function expectType<T>(_: T): void {
195195
// no op
196196
}
197+
198+
export function showUnloadedMessage(container: HTMLElement, subject: string): void {
199+
container.innerHTML = '';
200+
container.className = '';
201+
202+
const span = document.createElement('span');
203+
span.className = 'mb-warning mb-unloaded';
204+
span.innerText = `[MB_UNLOADED] ${subject}`;
205+
206+
container.appendChild(span);
207+
}

styles.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ code.mb-error {
381381
color: var(--text-error) !important;
382382
}
383383

384+
.mb-warning {
385+
color: var(--text-warning) !important;
386+
font-weight: bold;
387+
font-family: var(--font-monospace);
388+
}
389+
390+
code.mb-warning {
391+
color: var(--text-warning) !important;
392+
}
393+
384394
/* Code */
385395
.mb-code {
386396
color: var(--text-normal);

0 commit comments

Comments
 (0)