Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Aug 4, 2023
1 parent f783461 commit b00ae70
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/core/src/lib/widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ export class WidgetManager {
deck: Deck;
parentElement?: HTMLElement | null;

private widgets: Widget[] = [];
/** Widgets added via the imperative API */
private defaultWidgets: Widget[] = [];
/** Resolved widgets from both imperative and declarative APIs */
private widgets: Widget[] = [];
/** The last configs received from the declarative API */
private configs: WidgetConfig[] = [];
private containers: {[id: string]: HTMLDivElement} = {};
private lastViewports: {[id: string]: Viewport} = {};
private configs: WidgetConfig[] = [];

constructor({deck, parentElement}: {deck: Deck; parentElement?: HTMLElement | null}) {
this.deck = deck;
this.parentElement = parentElement;
}

// Declarative API
/** Declarative API to configure widgets */
setProps(props: {widgets?: WidgetConfig[]}) {
if (props.widgets && !deepEqual(props.widgets, this.configs, 1)) {
this._setConfigs(props.widgets);
Expand All @@ -105,7 +108,7 @@ export class WidgetManager {
}
}

// Imperative API, not affected by the declarative prop
/** Imperative API. Widgets added this way are not affected by the declarative prop. */
addDefault(
widget: Widget,
options?: {
Expand All @@ -117,10 +120,12 @@ export class WidgetManager {
const {viewId, placement} = normalizeConfig({widget, ...options});
this._add(widget, viewId, placement);
this.defaultWidgets.push(widget);
// Update widget list
this._setConfigs(this.configs);
}
}

/** Resolve widgets from the declarative prop */
private _setConfigs(nextConfigs: WidgetConfig[]) {
this.configs = nextConfigs;
const oldWidgetMap: Record<string, Widget | null> = {};
Expand Down

0 comments on commit b00ae70

Please sign in to comment.