-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80b1c63
commit f6862de
Showing
19 changed files
with
7,367 additions
and
8,124 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Dictionary as Dict } from "lodash"; | ||
import { Component, EventContext, Properties as Props } from "protocol"; | ||
import { CompiledComponent, EventContext, Properties as Props } from "protocol"; | ||
|
||
export type Context<T extends Props = {}> = | ||
| PropMap<T> | ||
| EventContext | ||
| Component<any, T>; | ||
| CompiledComponent<string, T>; | ||
|
||
export type Key<T> = Extract<keyof T, string>; | ||
|
||
export type Prop<T extends Props> = (ctx: Context<T>) => T[keyof T]; | ||
|
||
export type PropMap<T extends Props> = Dict<Prop<T>>; | ||
export type PropMap<T extends Props> = Dict<Prop<T>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,71 @@ | ||
import { get, keyBy, lowerCase as lower, memoize, startCase } from "lodash"; | ||
import { useMemo } from "react"; | ||
import { call } from "components/script-editor/call"; | ||
import { useSpecimen } from "slices/specimen"; | ||
import { useUIState } from "slices/UIState"; | ||
|
||
export function useBreakpoints() { | ||
const [{ specimen }] = useSpecimen(); | ||
const [{ code, breakpoints = [], monotonicF, monotonicG }] = useUIState(); | ||
import { | ||
get, | ||
keyBy, | ||
lowerCase as lower, | ||
memoize, | ||
noop, | ||
startCase, | ||
} from "lodash"; | ||
import { useCallback, useMemo } from "react"; | ||
import { call } from "components/script-editor/call"; | ||
import { useSpecimen } from "slices/specimen"; | ||
import { useUIState } from "slices/UIState"; | ||
|
||
return useMemo(() => { | ||
const memo = keyBy(specimen?.eventList, "id"); | ||
return memoize((step: number) => { | ||
const event = specimen?.eventList?.[step]; | ||
if (event) { | ||
try { | ||
// Check monotonic f or g values | ||
if (step) { | ||
for (const p of [monotonicF && "f", monotonicG && "g"]) { | ||
if (p && get(memo[`${event.pId}`], p) > get(event, p)) { | ||
return { result: `Monotonicity violation on ${p}` }; | ||
} | ||
} | ||
} | ||
// Check breakpoints in the breakpoints section | ||
for (const { | ||
active, | ||
condition, | ||
type, | ||
property = "", | ||
reference = 0, | ||
} of breakpoints) { | ||
const isType = !type || type === event.type; | ||
const match = condition?.apply?.(get(event, property), reference); | ||
if (active && isType && match) { | ||
return { | ||
result: `${property} ${lower( | ||
startCase(condition?.key) | ||
)} ${reference}`, | ||
}; | ||
} | ||
} | ||
// Check breakpoints in the script editor section | ||
if ( | ||
call(code ?? "", "shouldBreak", [ | ||
step, | ||
event, | ||
specimen?.eventList ?? [], | ||
]) | ||
) { | ||
return { result: "Script editor" }; | ||
} | ||
} catch (e) { | ||
return { error: `${e}` }; | ||
} | ||
} | ||
return { result: "" }; | ||
}); | ||
}, [code, specimen, breakpoints, monotonicF, monotonicG]); | ||
} | ||
export function useBreakpoints() { | ||
//TODO: | ||
// const [{ specimen }] = useSpecimen(); | ||
// const [{ code, breakpoints = [], monotonicF, monotonicG }] = useUIState(); | ||
// return useMemo(() => { | ||
// const memo = keyBy(specimen?.eventList, "id"); | ||
// return memoize((step: number) => { | ||
// const event = specimen?.eventList?.[step]; | ||
// if (event) { | ||
// try { | ||
// // Check monotonic f or g values | ||
// if (step) { | ||
// for (const p of [monotonicF && "f", monotonicG && "g"]) { | ||
// if (p && get(memo[`${event.pId}`], p) > get(event, p)) { | ||
// return { result: `Monotonicity violation on ${p}` }; | ||
// } | ||
// } | ||
// } | ||
// // Check breakpoints in the breakpoints section | ||
// for (const { | ||
// active, | ||
// condition, | ||
// type, | ||
// property = "", | ||
// reference = 0, | ||
// } of breakpoints) { | ||
// const isType = !type || type === event.type; | ||
// const match = condition?.apply?.(get(event, property), reference); | ||
// if (active && isType && match) { | ||
// return { | ||
// result: `${property} ${lower( | ||
// startCase(condition?.key) | ||
// )} ${reference}`, | ||
// }; | ||
// } | ||
// } | ||
// // Check breakpoints in the script editor section | ||
// if ( | ||
// call(code ?? "", "shouldBreak", [ | ||
// step, | ||
// event, | ||
// specimen?.eventList ?? [], | ||
// ]) | ||
// ) { | ||
// return { result: "Script editor" }; | ||
// } | ||
// } catch (e) { | ||
// return { error: `${e}` }; | ||
// } | ||
// } | ||
// return { result: "" }; | ||
// }); | ||
// }, [code, specimen, breakpoints, monotonicF, monotonicG]); | ||
return useCallback( | ||
(_i: number) => ({ result: "", error: undefined, offset: 0 }), | ||
[] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.