From 4e41f3df3f310fb986bf900ace105ab7da03c654 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 11 Jun 2024 08:29:06 +0530 Subject: [PATCH] feat: lazy-loading and standards compliance --- src/components/FlickerList.tsx | 2 +- src/index.tsx | 30 ++++++++++++++---------------- src/pages/main/Home.tsx | 40 +++++++++++++++++++--------------------- src/util/index.ts | 12 ++++++++++-- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/components/FlickerList.tsx b/src/components/FlickerList.tsx index d7218c1..326b6a2 100644 --- a/src/components/FlickerList.tsx +++ b/src/components/FlickerList.tsx @@ -136,7 +136,7 @@ const FlickerList: React.FC<{ )), -
  • ยท
  • , + index =>
  • ยท
  • , ), ]} diff --git a/src/index.tsx b/src/index.tsx index 6f15d3b..92fa0b2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,20 +1,16 @@ -import React from "react"; - +import React, { lazy, Suspense } from "react"; import { createRoot } from "react-dom/client"; - import useLocation from "wouter/use-location"; -import Home from "./pages/main/Home"; -import Exp from "./pages/main/Exp"; -import Projects from "./pages/main/Projects"; -import Contact from "./pages/main/Contact"; -import Live from "./pages/main/Live"; - -import NotFound from "./pages/main/404"; -import BlogHome from "./pages/blog/Home"; -import { BlogPost } from "./pages/blog/components/BlogContent"; import { normalise } from "./util"; +const Home = lazy(() => import("./pages/main/Home")); +const Exp = lazy(() => import("./pages/main/Exp")); +const Projects = lazy(() => import("./pages/main/Projects")); +const Contact = lazy(() => import("./pages/main/Contact")); + +const NotFound = lazy(() => import("./pages/main/404")); + function App() { const [location, navigate] = useLocation(); @@ -30,14 +26,16 @@ function App() { if (normalised.startsWith("/experience/")) return ; if (normalised === "/projects") return ; if (normalised === "/contact") return ; - if (normalised === "/live") return ; - if (normalised === "/blog") return ; - if (location.startsWith("/blog")) return ; + // if (normalised === "/live") return ; + // if (normalised === "/blog") return ; + // if (location.startsWith("/blog")) return ; return ; } createRoot(document.getElementById("root")!).render( - + + + , ); diff --git a/src/pages/main/Home.tsx b/src/pages/main/Home.tsx index 3d28eb1..21b68bc 100644 --- a/src/pages/main/Home.tsx +++ b/src/pages/main/Home.tsx @@ -17,27 +17,25 @@ const Home: React.FC = () => {

    MKRhere

    -

    - -

    +
    new Promise(r => setTimeout(r, t)); -export function* intersperse(xs: T[], delim: U): Generator { +export function* intersperse( + xs: T[], + delim: (index: number) => U, +): Generator { let first = true; + let i = 0; for (const x of xs) { - if (!first) yield delim; + if (!first) { + yield delim(i); + i++; + } first = false; yield x; + i++; } }