Skip to content

Commit

Permalink
Proxy rework
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Sep 18, 2024
1 parent ff17c04 commit fc232a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
13 changes: 12 additions & 1 deletion packages/dom/src/core/entities/droppable/droppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ export class Droppable<T extends Data = Data> extends AbstractDroppable<
}

@reactive
public accessor element: Element | undefined;
accessor #element: Element | undefined;

@reactive
public accessor proxy: Element | undefined;

set element(element: Element | undefined) {
this.#element = element;
}

get element() {
return this.proxy ?? this.#element;
}

public refreshShape: () => Shape | undefined;
}
23 changes: 2 additions & 21 deletions packages/dom/src/core/plugins/feedback/Feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,33 +511,14 @@ function createPlaceholder(source: Draggable) {

let current = droppable.element;

droppable.element = clonedElement;
droppable.proxy = clonedElement;
clonedElement.removeAttribute(IDENTIFIER_ATTRIBUTE);

ProxiedElements.set(current, clonedElement);

const proxy = Proxy.revocable(droppable, {
set(target, key, newValue) {
if (key === 'element') {
ProxiedElements.delete(current);

if (newValue instanceof Element) {
ProxiedElements.set(newValue, clonedElement);
}

current = newValue;

return false;
}

return Reflect.set(target, key, newValue);
},
});

cleanup.push(() => {
proxy.revoke();
ProxiedElements.delete(current);
droppable.element = current;
droppable.proxy = undefined;
});
}

Expand Down

0 comments on commit fc232a7

Please sign in to comment.