From dc601637a8a3000311c1efdb88fe075a235e776f Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Tue, 24 Jan 2023 17:28:17 -0500 Subject: [PATCH] collapse context reset --- js/people.js | 18 +++++++++++------- js/tree.js | 29 ++++++++++++++++++----------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/js/people.js b/js/people.js index 596d9c5..892d654 100644 --- a/js/people.js +++ b/js/people.js @@ -89,16 +89,20 @@ export default () => {
<${PersonForm}/> <${PersonTable}/> + <${Tree.Branch}> - <${Tree.Button}> - <${Tree.Menu}> -
-

- The method addEventListener() works by adding a function, or an object that implements EventListener, to the list of event listeners for the specified event type on the EventTarget on which it's called. If the function or object is already in the list of event listeners for this target, the function or object is not added a second time. -

-
+ <${Tree.Button}/> + <${Tree.Menu} class="shadow-lg rounded-lg bg-white"> +

hey

+ <${Tree.Branch}> + <${Tree.Button} class="p-4 bg-red-500 text-white"/> + <${Tree.Menu}> +

sup.

+ + +
`; }; diff --git a/js/tree.js b/js/tree.js index 658f9ec..cb2f9e6 100644 --- a/js/tree.js +++ b/js/tree.js @@ -1,7 +1,7 @@ import { html } from "htm"; import * as React from "preact"; -/** @typedef {({children, classes}:{children:preact.VNode, classes:string|null})=>preact.VNode} BasicElement */ +/** @typedef {(props:{children:preact.VNode, class:string|null})=>preact.VNode} BasicElement */ /** @typedef {{Open:boolean, Done:boolean}} Stage*/ /** @typedef {[set:Stage, get:React.StateUpdater]} Binding */ @@ -9,6 +9,8 @@ const BranchContext = React.createContext( /** @type Binding */ ([{ Open: false, Done: true }, (_n) => {}]), ); +export { BranchContext as Context }; + /** @type BasicElement */ export const Branch = (props) => { /** @type Binding */ const stage = React.useState( @@ -17,7 +19,8 @@ export const Branch = (props) => { /** @type Binding */ const stageParent = React.useContext(BranchContext); React.useEffect(() => { - const [{ Open, Done }, Shut] = stageParent; + const [{ Open, Done }] = stageParent; + const [, Shut] = stage; if (!Open && Done) { Shut({ Open: false, Done: true }); } @@ -40,7 +43,7 @@ export const Button = (props) => { console.log(value); }; - return html`