Skip to content

Commit

Permalink
semantic nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Sep 3, 2024
1 parent f0b32da commit 203499d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
11 changes: 11 additions & 0 deletions website/src/components/MonacoPlayground/BothEditors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import InputEditor from "./InputEditor";
import OutputEditor from "./OutputEditor";

export default function BothEditors() {
return (
<>
<InputEditor />
<OutputEditor />
</>
);
}
17 changes: 16 additions & 1 deletion website/src/components/PlaygroundFeatures/ConfigBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import store, {
getNullableByDefault,
getOutputOption,
getSemanticNullability,
getShowGratsDirectives,
useAppSelector,
} from "./store";
Expand All @@ -11,6 +12,7 @@ import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

export default function ConfigBar(): JSX.Element {
const nullableByDefault = useAppSelector(getNullableByDefault);
const semanticNullability = useAppSelector(getSemanticNullability);
const showGratsDirectives = useAppSelector(getShowGratsDirectives);
const outputOption = useAppSelector(getOutputOption);
const { gitHash } = useDocusaurusContext().siteConfig.customFields as {
Expand Down Expand Up @@ -44,7 +46,20 @@ export default function ConfigBar(): JSX.Element {
});
}}
/>
Make fields nullable by default
Nullable by default
</Label>
<Label>
<input
checked={semanticNullability}
type="checkbox"
onChange={(e) => {
store.dispatch({
type: "SEMANTIC_NULLABILITY_INPUT_CHANGED",
value: e.target.checked,
});
}}
/>
Semantic nullability
</Label>
</ConfigBlock>
<div style={{ display: "flex", gap: "1em" }}>
Expand Down
29 changes: 28 additions & 1 deletion website/src/components/PlaygroundFeatures/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type State = {
doc: string;
config: {
nullableByDefault: boolean;
strictSemanticNullability: boolean;
reportTypeScriptTypeErrors: boolean;
};
view: {
Expand Down Expand Up @@ -42,6 +43,10 @@ export type Action =
type: "DEFAULT_NULLABLE_INPUT_CHANGED";
value: boolean;
}
| {
type: "SEMANTIC_NULLABILITY_INPUT_CHANGED";
value: boolean;
}
| {
type: "GRATS_EMITTED_NEW_RESULT";
graphql: string;
Expand Down Expand Up @@ -84,14 +89,32 @@ function reducer(state: State = stateFromUrl(), action: Action) {
outputOption: action.value,
},
};
case "DEFAULT_NULLABLE_INPUT_CHANGED":
case "DEFAULT_NULLABLE_INPUT_CHANGED": {
const strictSemanticNullability = action.value
? state.config.strictSemanticNullability
: false;
return {
...state,
config: {
...state.config,
strictSemanticNullability,
nullableByDefault: action.value,
},
};
}
case "SEMANTIC_NULLABILITY_INPUT_CHANGED": {
const nullableByDefault = action.value
? true
: state.config.nullableByDefault;
return {
...state,
config: {
...state.config,
nullableByDefault,
strictSemanticNullability: action.value,
},
};
}
case "GRATS_EMITTED_NEW_RESULT":
return {
...state,
Expand Down Expand Up @@ -176,6 +199,10 @@ export function getNullableByDefault(state): boolean {
return state.config.nullableByDefault;
}

export function getSemanticNullability(state): boolean {
return state.config.strictSemanticNullability;
}

export function getShowGratsDirectives(state): boolean {
return state.view.showGratsDirectives;
}
Expand Down
10 changes: 3 additions & 7 deletions website/src/pages/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import BrowserOnly from "@docusaurus/BrowserOnly";
import FillRemainingHeight from "../../components/PlaygroundFeatures/FillRemainingHeight";
import { bindGratsToStore } from "../../components/PlaygroundFeatures/gratsStoreBindings";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
const InputEditor = React.lazy(
() => import("../../components/MonacoPlayground/InputEditor"),
);
const OutputEditor = React.lazy(
() => import("../../components/MonacoPlayground/OutputEditor"),
const BothEditors = React.lazy(
() => import("../../components/MonacoPlayground/BothEditors"),
);

if (ExecutionEnvironment.canUseDOM) {
Expand Down Expand Up @@ -68,8 +65,7 @@ export default function EditorView() {
</div>
}
>
<InputEditor />
<OutputEditor />
<BothEditors />
</Suspense>
</div>
</div>
Expand Down

0 comments on commit 203499d

Please sign in to comment.