perf: reduce bundle size of some pages

This commit is contained in:
rusconn
2023-06-15 18:44:39 +09:00
parent 6612a3be2d
commit 4d198c5b96
10 changed files with 27 additions and 24 deletions

View File

@@ -1,7 +1,6 @@
"use client";
import { useCallback, useMemo, useState } from "react";
import * as O from "fp-ts/lib/Option";
import yaml from "js-yaml";
import { toolGroups } from "@/config/tools";
@@ -45,7 +44,7 @@ export default function Page() {
setForm(prev => ({
...prev,
json: text,
yaml: O.isNone(parsed)
yaml: parsed.isErr()
? ""
: yaml.dump(parsed.value, { indent: prev.indentation.length, quotingType: '"' }),
}));
@@ -57,7 +56,7 @@ export default function Page() {
setForm(prev => ({
...prev,
yaml: text,
json: O.isNone(parsed) ? "" : JSON.stringify(parsed.value, null, prev.indentation),
json: parsed.isErr() ? "" : JSON.stringify(parsed.value, null, prev.indentation),
}));
}, []);
@@ -68,7 +67,7 @@ export default function Page() {
const onIndentationChange: SelectProps["onValueChange"] = value => {
const parsed = safeJsonParse(form.json);
const jsonYaml = O.isNone(parsed)
const jsonYaml = parsed.isErr()
? { json: "", yaml: "" }
: {
json: JSON.stringify(parsed.value, null, value),

View File

@@ -1,7 +1,6 @@
"use client";
import { useCallback, useMemo, useState } from "react";
import * as O from "fp-ts/lib/Option";
import { toolGroups } from "@/config/tools";
import { decode } from "@/lib/jwt";
@@ -21,8 +20,8 @@ export default function Page() {
);
const { header: h, payload: p } = decode(jwt);
const header = O.isNone(h) ? "" : JSON.stringify(h.value, null, 2);
const payload = O.isNone(p) ? "" : JSON.stringify(p.value, null, 2);
const header = h.isErr() ? "" : JSON.stringify(h.value, null, 2);
const payload = p.isErr() ? "" : JSON.stringify(p.value, null, 2);
const clearJwt = useCallback(() => setJwt(""), []);

View File

@@ -1,8 +1,6 @@
"use client";
import { useCallback, useMemo, useState } from "react";
import { constant } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import { toolGroups } from "@/config/tools";
import { safeDecodeURIComponent, safeEncodeURIComponent } from "@/lib/uri";
@@ -24,14 +22,14 @@ export default function Page() {
const setDecodedReactively = useCallback((text: string) => {
setForm({
decoded: text,
encoded: O.getOrElse(constant(""))(safeEncodeURIComponent(text)),
encoded: safeEncodeURIComponent(text).unwrapOr(""),
});
}, []);
const setEncodedReactively = useCallback((text: string) => {
setForm({
encoded: text,
decoded: O.getOrElse(constant(""))(safeDecodeURIComponent(text)),
decoded: safeDecodeURIComponent(text).unwrapOr(""),
});
}, []);

View File

@@ -1,7 +1,6 @@
"use client";
import { useCallback, useMemo, useState } from "react";
import * as O from "fp-ts/lib/Option";
import { toolGroups } from "@/config/tools";
import { safeJsonParse } from "@/lib/json";
@@ -36,7 +35,7 @@ export default function Page() {
const [input, setInput] = useState('{\n"foo":"bar"\n}');
const parsed = safeJsonParse(input);
const output = O.isNone(parsed) ? "" : JSON.stringify(parsed.value, null, indentation);
const output = parsed.isErr() ? "" : JSON.stringify(parsed.value, null, indentation);
const clearInput = useCallback(() => setInput(""), []);