diff --git a/src/store.js b/src/store.js index 9f61a19..9f35e92 100644 --- a/src/store.js +++ b/src/store.js @@ -13,7 +13,8 @@ export const ColumnMapping = [ [6000, size*5.5, false], [8000, size*6.0, true ] ]; -/** @type {(inFrequency:number)=>Store.ColumnMapping|false} */ +/** Looks up a frequency in ColumnMapping + * @type {(inFrequency:number)=>Store.ColumnMapping|false} */ export const ColumnLookup =(inFrequency)=> { for(let i=0; i return false; }; +/** Creates a new Store.Context object that contain the current selections + * @type {(inState:Store.State, inTest?:Store.Test)=>Store.Context} */ +const Reselect =(inState, inTest)=> +{ + /** @type {Store.Context} */ + const output = { Test:inTest??inState.Live.Test }; + const column = ColumnMapping[inState.Freq.Value]; + if(column && output.Test) + { + const hz = column[0]; + for(let i=0; iStore.TestFrequencySample|undefined} */ -export const MarkGet =(freq, chan, user)=> freq[/** @type {Store.PlotKey} */ (`${user ? "User" : "Test"}${chan ? "R" : "L"}`)]; +/** Creates a new Store.DrawGroup object for the given Test and settings + * @type {(inTest:Store.Test|undefined, inChan:number, inStim:Store.Range, inIsUser:boolean)=>Store.DrawGroup} */ +const Redraw =(inTest, inChan, inStim, inIsUser)=> +{ + /** @type {Store.DrawGroup} */ + const output = {Points:[], Paths:[]}; + if(inTest) + { + let plot; + for(let i=0; iStore.Context} */ -const Reselect =(inState, inTest)=> -{ - /** @type {Store.Context} */ - const output = { Test:inTest??inState.Live.Test }; - const column = ColumnMapping[inState.Freq.Value]; - if(column && inState.Live.Test) - { - const hz = column[0]; - for(let i=0; iStore.DrawGroup} */ -const Redraw =(inTest, inChan, inStim, inIsUser)=> -{ - /** @type {Store.DrawGroup} */ - const output = {Points:[], Paths:[]}; - - if(inTest) - { - let plot; - for(let i=0; i tone.Max){ tone.Value = tone.Max; } - clone[Name] = tone; - if(Name != "Stim") - { - clone.Live = Reselect(clone); - } - } - - return clone; -} - - /** @type {preact.Context} */ export const Context = React.createContext([Initial, (_a)=>{}]); + /** @type {(props:{children:preact.ComponentChildren})=>preact.VNode} */ export const Provider =(props)=> { - const initialized = Reducer(Initial, {Name:"Test", Data:0}); /** @type {Store.Binding} */ - const reducer = React.useReducer(Reducer, initialized); + const reducer = React.useReducer(Reducer, Initial, ()=>Reducer(Initial, {Name:"Test", Data:0})); return React.createElement(Context.Provider, {value:reducer, children:props.children}); -} +}; + /** @type {()=>Store.Binding} */ export const Consumer =()=> React.useContext(Context); \ No newline at end of file diff --git a/store.d.ts b/store.d.ts index c9cec84..93701ab 100644 --- a/store.d.ts +++ b/store.d.ts @@ -25,12 +25,7 @@ declare namespace Store { Freq: Range; Stim: Range; Live: Context; - Draw: { - UserL: DrawGroup; - UserR: DrawGroup; - TestL: DrawGroup; - TestR: DrawGroup; - }; + Draw: DrawTest; Tests: Array; }; @@ -50,8 +45,7 @@ declare namespace Store { type DrawPoint = { X: number; Y: number; Mark: TestFrequencySample }; type DrawLine = { Head:DrawPoint, Tail:DrawPoint}; type DrawGroup = { Points: Array; Paths: Array }; - type DrawChart = { Left: DrawGroup; Right: DrawGroup }; - type DrawTest = { User?: DrawChart; Test?: DrawChart }; + type DrawTest = { UserL: DrawGroup, UserR: DrawGroup, TestL: DrawGroup, TestR: DrawGroup }; type Binding = [state:State, dispatch:(inAction:Action)=>void] }