Skip to content

Commit

Permalink
Conditional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Feb 23, 2024
1 parent 32d20dc commit 1193942
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@
const queryParams = new URLSearchParams(window.location.search);
for (const { name, isValid, selector, defaultValue } of params) {
const value = queryParams.get(name);
const newValue = isValid(value) ? value : defaultValue
queryParams.set(name, newValue);
selector.value = newValue
selector.value = isValid(value) ? value : defaultValue
}
history.replaceState(null, null, "?"+queryParams.toString());
return () => {
for (let { name, selector } of params) {
for (const { name, selector, when, defaultValue } of params) {
if (selector.disabled = (when && !when(Object.fromEntries(queryParams)))) {
selector.value = defaultValue
}
queryParams.set(name, selector.value);
}
history.pushState(null, null, "?"+queryParams.toString());
Expand Down Expand Up @@ -300,19 +300,22 @@
name: "impl",
selector: raylibImplSelect,
defaultValue: defaultImpl,
isValid: (value) => value in impls
isValid: (value) => value in impls,
when: ({ env }) => env === "worker",
},
{
name: "ctx",
selector: raylibCtxSelect,
defaultValue: defaultCtx,
isValid: (value) => value in ctxs
isValid: (value) => value in ctxs,
when: ({ impl }) => impl !== IMPL.GAME_FRAME
},
{
name: "rnd",
selector: raylibRendererSelect,
defaultValue: defaultRenderer,
isValid: (value) => value in renderers
isValid: (value) => value in renderers,
when: ({ impl }) => impl !== IMPL.GAME_FRAME
}
)
const showWarning = makeWarningShower(
Expand Down

0 comments on commit 1193942

Please sign in to comment.