Skip to content

Commit

Permalink
Clean up some typing in website
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Apr 20, 2024
1 parent 009864e commit 808a452
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
43 changes: 25 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Expand Up @@ -33,6 +33,7 @@
"@graphql-tools/utils": "^9.2.1",
"@mdx-js/react": "^1.6.22",
"@types/node": "^18.15.0",
"@types/react": "^18",
"@typescript/vfs": "1.5.0",
"clsx": "^1.2.1",
"cm6-graphql": "^0.0.3",
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/GratsCode.tsx
Expand Up @@ -22,7 +22,7 @@ export default function GratsCode({ out, mode }: Props) {
throw new Error("Expected children to be special grats code");
}
return chunks;
});
}, [out]);

switch (mode) {
case "ts":
Expand Down
15 changes: 10 additions & 5 deletions website/src/components/PlaygroundFeatures/editors/InputView.tsx
Expand Up @@ -15,13 +15,14 @@ import { getConfig, getDoc, getView, onSelectorChange } from "../store";
import { createSelector } from "reselect";
import { Theme } from "./theme";
import store, { useUrlState } from "../store";
import { GratsConfig } from "grats";

export default function InputView() {
useEffect(() => {
store.dispatch({ type: "SET_STATE_FROM_URL" });
}, []);
useUrlState(store);
const [ref, setRef] = useState(null);
const [ref, setRef] = useState<HTMLDivElement | null>(null);
const fsMap = useFsMap();
useEffect(() => {
if (ref != null && fsMap != null) {
Expand All @@ -41,7 +42,7 @@ export default function InputView() {
}

function useFsMap() {
const [fsMap, setFsMap] = useState(null);
const [fsMap, setFsMap] = useState<Map<string, string> | null>(null);

useEffect(() => {
let unmounted = false;
Expand Down Expand Up @@ -71,9 +72,13 @@ async function createInputView(store, fsMap, left) {
const state = store.getState();

// Create a selector that memoizes the linter and closes over the fsMap
const getLinter = createSelector(getView, getConfig, (view, config) => {
return createLinter(fsMap, view, config);
});
const getLinter = createSelector(
getView,
getConfig,
(view, config: GratsConfig) => {
return createLinter(fsMap, view, config);
},
);

const linter = getLinter(state);

Expand Down
12 changes: 10 additions & 2 deletions website/src/components/PlaygroundFeatures/linter.ts
Expand Up @@ -26,7 +26,11 @@ if (ExecutionEnvironment.canUseDOM) {
};
}

function buildSchemaResultWithFsMap(fsMap, text: string, config: GratsConfig) {
function buildSchemaResultWithFsMap(
fsMap: Map<string, string>,
text: string,
config: GratsConfig,
) {
fsMap.set("index.ts", text);
fsMap.set(GRATS_PATH, GRATS_TYPE_DECLARATIONS);
// TODO: Don't recreate the system each time!
Expand Down Expand Up @@ -65,7 +69,11 @@ function buildSchemaResultWithFsMap(fsMap, text: string, config: GratsConfig) {
}
}

export function createLinter(fsMap, view, config: GratsConfig) {
export function createLinter(
fsMap: Map<string, string>,
view,
config: GratsConfig,
) {
return linter((codeMirrorView) => {
const text = codeMirrorView.viewState.state.doc.toString();

Expand Down
14 changes: 12 additions & 2 deletions website/tsconfig.json
Expand Up @@ -2,6 +2,16 @@
// This file is not used in compilation. It is here just for a nice editor experience.
"extends": "@tsconfig/docusaurus/tsconfig.json",
"compilerOptions": {
"baseUrl": "."
}
"baseUrl": ".",
"skipLibCheck": true,
// typescript options here
"experimentalDecorators": true,
"outDir": "dist",
"downlevelIteration": true,
"strictNullChecks": true,
"declaration": true,
"resolveJsonModule": true,
"strictPropertyInitialization": true
},
"exclude": ["node_modules", "build", "**/*.grats.ts"]
}

0 comments on commit 808a452

Please sign in to comment.