Skip to content

Commit

Permalink
Fix inconsistencies with removed DOM elements
Browse files Browse the repository at this point in the history
Fix #293
  • Loading branch information
titouanmathis committed Sep 10, 2024
1 parent 596b0ad commit de945b1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/ui/atoms/Data/DataBind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';
import { isArray } from '@studiometa/js-toolkit/utils';
import { isInput, isCheckbox, isSelect } from './utils.js';

const instances = new Map<string, Set<DataBind>>();
const groups = new Map<string, Set<DataBind>>();

export interface DataBindProps extends BaseProps {
$options: {
Expand All @@ -24,11 +24,15 @@ export class DataBind<T extends BaseProps = BaseProps> extends Base<DataBindProp
get relatedInstances() {
const { name } = this.$options;

if (!instances.has(name)) {
instances.set(name, new Set());
const instances = groups.get(name) ?? groups.set(name, new Set()).get(name);

for (const instance of instances) {
if (!instance.$el.isConnected) {
instances.delete(instance);
}
}

return instances.get(name);
return instances;
}

get multiple() {
Expand Down

0 comments on commit de945b1

Please sign in to comment.