We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 755dff2 + 3ff3b60 commit 99b3b32Copy full SHA for 99b3b32
src/core/dom.js
@@ -279,6 +279,18 @@ const set_data = (el, name, value) => {
279
el[`${DATA_PREFIX}${name}`] = value;
280
};
281
282
+/**
283
+ * Delete a variable from the node instance.
284
+ * We are using a prefix to make sure the data doesn't collide with other attributes.
285
+ *
286
+ * @param el {Node} - The DOM node which we want to delete the variable from.
287
+ * @param name {String} - The name of the variable. Note - this is stored on
288
+ * the DOM node prefixed with the DATA_PREFIX.
289
+ */
290
+const delete_data = (el, name) => {
291
+ delete el[`${DATA_PREFIX}${name}`];
292
+};
293
+
294
/**
295
* Simple template engine, based on JS template literal
296
*
@@ -315,6 +327,7 @@ const dom = {
315
327
find_scroll_container: find_scroll_container,
316
328
get_data: get_data,
317
329
set_data: set_data,
330
+ delete_data: delete_data,
318
331
template: template,
319
332
add_event_listener: events.add_event_listener, // BBB export. TODO: Remove in an upcoming version.
320
333
remove_event_listener: events.remove_event_listener, // BBB export. TODO: Remove in an upcoming version.
src/core/dom.test.js
@@ -696,7 +696,7 @@ describe("core.dom tests", () => {
696
});
697
698
699
- describe("set_data, get_data", function () {
+ describe("set_data, get_data, delete_data", function () {
700
it("can be used to store and retrieve data on DOM nodes.", function () {
701
const el = document.createElement("div");
702
dom.set_data(el, "test_data", "hello.");
@@ -715,6 +715,13 @@ describe("core.dom tests", () => {
715
expect(dom.get_data(el, "test_data", null)).toBe(null);
716
expect(dom.get_data(el, "test_data")).toBe(undefined);
717
718
+ it("can also delete the data from dom nodes.", function () {
719
+ const el = document.createElement("div");
720
+ dom.set_data(el, "test_data", "hello.");
721
+ expect(dom.get_data(el, "test_data")).toBe("hello.");
722
+ dom.delete_data(el, "test_data");
723
+ expect(dom.get_data(el, "test_data")).toBe(undefined);
724
+ });
725
726
727
describe("template", () => {
src/pat/inject/inject.js
@@ -768,11 +768,11 @@ const inject = {
768
// Wait for the next tick to ensure that the close-panel listener
769
// is called before this one, even for non-async local injects.
770
await utils.timeout(1);
771
+ // Remove the close-panel event listener.
772
+ events.remove_event_listener($el[0], "pat-inject--close-panel");
773
// Only close the panel if a close-panel event was catched previously.
774
if (do_close_panel) {
775
do_close_panel = false;
- // Remove the close-panel event listener.
- events.remove_event_listener($el[0], "pat-inject--close-panel");
776
// Re-trigger close-panel event if it was caught while injection was in progress.
777
$el[0].dispatchEvent(
778
new Event("close-panel", { bubbles: true, cancelable: true })
0 commit comments