From d93daf81ea95012f92eda84231a8041cd5872ed7 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 3 Dec 2022 22:51:22 -0500 Subject: [PATCH] jsdoc woes chipping away --- src/app.js | 27 ++++++++++++++++++++++++--- src/store.js | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index be31cc0..40b2c2a 100644 --- a/src/app.js +++ b/src/app.js @@ -6,8 +6,12 @@ import TWPreAuto from "https://esm.sh/@twind/preset-autoprefix@1.0.1"; import * as UI from "./ui.js"; import { Reducer, Initial } from "./store.js"; import React from "https://esm.sh/preact@10.11.3/compat"; -import {html} from "https://esm.sh/htm@3.1.1/preact"; +import {html} from "https://esm.sh/htm@3.1.1/preact"; +/** @typedef {import("./store.js").State} State */ +/** @typedef {import("https://esm.sh/preact@10.11.3/compat").JSX.Element} JSX.Element */ +/** @typedef {import("./store.js").Action} Action */ +/** @type {JSX.Element} */ /** @type {TW.TwindConfig} */ const Configure = { @@ -76,25 +80,42 @@ ShadowDOM.append(ShadowCSS); ShadowDOM.append(ShadowDiv); TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv); +/** @type {import("https://esm.sh/v99/preact@10.11.3/src/index.js").Context} */ +const StoreContext = React.createContext([Initial, (a)=>{}]); -const StoreContext = React.createContext(null); const StoreProvider =(props)=> { const reducer = React.useReducer(Reducer, Initial); return html`<${StoreContext.Provider} value=${reducer}>${props.children}`; } + +/** @typedef {[state:State, dispatch:(inAction:Action)=>void]} Binding */ +/** @type {()=>Binding} */ const StoreConsumer =()=> React.useContext(StoreContext); const Deep =()=> { - const [State, Dispatch] = React.useContext(StoreContext); + const [State, Dispatch] = StoreConsumer(); return html` <${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:1})} disabled=${State.Stim.Value == State.Stim.Max}> ${State.Stim.Value} `; } +const Audiogram =()=> +{ + const [State, Dispatch] = StoreConsumer(); + return html` + + ${State.Draw} + <${UI.Mark} right=${false} x=${"10%"} y="20%" response=${true} /> + <${UI.Mark} right=${false}/> + + + `; +} + React.render(html` <${StoreProvider}> <${UI.Button} icon="+">hey! diff --git a/src/store.js b/src/store.js index 96113fd..c523e4a 100644 --- a/src/store.js +++ b/src/store.js @@ -37,7 +37,7 @@ export const MarkSet =(freq, chan, mark)=> freq[ chan ? "UserR" : "UserL" ] = ma /** @typedef {{Hz:number, TestL:TestFrequencySample, TestR:TestFrequencySample, UserL?:TestFrequencySample, UserR?:TestFrequencySample}} TestFrequency */ /** @typedef {{Name:string, Plot:Array}} Test */ /** @typedef {{Test?:Test, Freq?:TestFrequency, Mark?:TestFrequencySample}} Context */ -/** @typedef {{Chan:Range, Freq:Range, Stim:Range, Live:Context, Draw:{UserL:DrawGroup, UserR:DrawGroup, TestL:DrawGroup, TestR:DrawGroup}, Tests:Array}} State */ +/** @typedef {{Chan:Range, Freq:Range, Stim:Range, Live:Context, Draw:{UserL:DrawGroup, UserR:DrawGroup, TestL:DrawGroup, TestR:DrawGroup}, Tests:Array}} State @memberof Store*/ /** @type {State} */ export const Initial = {