This is a demonstration project showcasing the capabilities of the rEFui JavaScript library for building reactive user interfaces. It's a simple, yet functional, Hacker News client built with rEFui and Vite.
- Reactive UI: Built with rEFui, showcasing its signal-based reactivity model.
- Multiple Sections: Browse Top, New, Best, Ask, Show, and Job stories.
- Resizable Panels: The story list and comment view are in resizable panels for a flexible layout.
- Dark Mode: Toggle between light and dark themes.
- Infinite Scroll: "Load More" functionality for both the story list and nested comments.
- Asynchronous Components: Demonstrates loading data within components and handling loading/error states gracefully.
- Component-Based Architecture: The application is structured into reusable components for stories and comments.
- Direct DOM Rendering: Utilizes
refui/domfor efficient, direct manipulation of the DOM. - Vite + HMR: Fast development experience with Vite and the
refurbishplugin for Hot Module Replacement.
- Framework: rEFui
- Build Tool: Vite
- Reactivity Plugin: refurbish (for HMR)
- API: Hacker News Firebase API
-
Clone the repository:
git clone https://github.com/ClassicOldSong/refui-hackernews-demo.git cd refui-hackernews-demo -
Install dependencies:
pnpm install
-
Run the development server:
pnpm dev
The application will be available at
http://localhost:5173(or another port if 5173 is in use).
To create a production build, run:
pnpm buildThe optimized files will be located in the dist/ directory. You can preview the production build with pnpm preview.
This project serves as a practical example for several core rEFui concepts:
signalandwatch: Used extensively for managing state like the current story section, loading status, and dark mode.- Computed Signals (
$): Used to derive state, such as the list of stories to display from the full list. - Asynchronous Components:
StoryItem.jsxandCommentItem.jsxareasynccomponents that fetch their own data and manage their lifecycle. The<Async>component (used implicitly byasynccomponents) handles pending (fallback) and rejected (catch) states. <For>Component: Used to efficiently render the list of stories and comments.<If>Component: Used for conditional rendering of UI elements like loading indicators, "Load More" buttons, and the comment view.- DOM Renderer: The project is initialized with
createDOMRendererto render the UI directly to the DOM. - Event Handling: Uses
on:eventsyntax for handling user interactions like clicks and mouse-down for the resizer.
This project is licensed under the MIT License. See the LICENSE file for details.