@atomico/hooks
Advanced tools
Comparing version 3.11.0 to 3.11.1
{ | ||
"name": "@atomico/hooks", | ||
"description": "Series of utilities in hooks format to extend the operation of Atomico", | ||
"version": "3.11.0", | ||
"version": "3.11.1", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "workspaces": [ |
@@ -1,2 +0,2 @@ | ||
import { useState, useEffect } from "atomico"; | ||
import { useState, useEffect, Mark } from "atomico"; | ||
/** | ||
@@ -12,6 +12,10 @@ * | ||
const type = "slotchange"; | ||
// Take the existing children | ||
setChildNodes(current.assignedNodes()); | ||
// handler subscriber to the event | ||
const handler = () => setChildNodes(current.assignedNodes()); | ||
const handler = () => | ||
setChildNodes( | ||
current.assignedNodes().filter((child) => !(child instanceof Mark)) | ||
); | ||
// First load | ||
handler(); | ||
// listener and unlistener | ||
@@ -18,0 +22,0 @@ current.addEventListener(type, handler); |
import { expect } from "@esm-bundle/chai"; | ||
import { Mark } from "atomico"; | ||
import { createHooks } from "atomico/test-hooks"; | ||
@@ -24,1 +25,21 @@ import { useSlot } from "./use-slot.js"; | ||
}); | ||
it("avoid Mark", () => { | ||
const current = document.createElement("slot"); | ||
const host = document.createElement("div"); | ||
host.append(new Mark("Hidden")); | ||
host.attachShadow({ mode: "open" }).append(current); | ||
const ref = { current }; | ||
const hooks = createHooks(() => { | ||
expect(render()).to.deep.equal([]); // next render | ||
}); | ||
const render = () => hooks.load(() => useSlot(ref)); | ||
render(); // first render | ||
hooks.cleanEffects()(); | ||
}); |
48378
1419