Skip to content

Commit

Permalink
* core: add z-use to elements with components instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Nov 13, 2024
1 parent a8d046d commit ef3bc4d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/core/src/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ export class Component<O extends {} = {}, E extends ComponentEventsDefnition = {
this.resetOptions(options);
this._key = this.options.key ?? `__${gid}`;

if (ALL.has(element)) {
ALL.get(element)!.add(this);
let all = ALL.get(element);
if (all) {
all.add(this);
} else {
ALL.set(element, new Set([this]));
all = new Set([this]);
ALL.set(element, all);
}

if (TYPED_ALL.has(NAME)) {
Expand All @@ -164,7 +166,7 @@ export class Component<O extends {} = {}, E extends ComponentEventsDefnition = {
TYPED_ALL.set(NAME, new Set([this]));
}

$element.data(KEY, this).attr(ATTR_KEY, '').attr(DATA_KEY, `${gid}`);
$element.data(KEY, this).attr(ATTR_KEY, '').attr(DATA_KEY, `${gid}`).attr('z-use', [...new Set([...all].map(x => x.constructor.NAME))].join(','));
if (MULTI_INSTANCE) {
const dataName = `${KEY}:ALL`;
let instanceMap: Map<string | number, Component> | undefined = $element.data(dataName);
Expand Down Expand Up @@ -310,6 +312,13 @@ export class Component<O extends {} = {}, E extends ComponentEventsDefnition = {
}
}

const useAll = ALL.get(element);
if (!useAll?.size) {
$element.removeAttr('z-use');
} else {
$element.attr('z-use', [...new Set([...useAll].map(x => x.constructor.NAME))].join(','));
}

this.options.$onDestroy?.call(this);
}

Expand Down

0 comments on commit ef3bc4d

Please sign in to comment.