### Install rEFui and refurbish dependencies with bun Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Installs the 'refui' library and 'refurbish' (for HMR) using bun. These are essential for running rEFui applications with Vite. ```bash bun add refui bun add -d refurbish ``` -------------------------------- ### Run Vite development server with bun Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to start the Vite development server using bun. This command compiles the project and serves it locally for development. ```bash bun run dev ``` -------------------------------- ### Install rEFui and refurbish dependencies with npm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Installs the 'refui' library and 'refurbish' (for HMR) using npm. These are essential for running rEFui applications with Vite. ```bash npm i refui npm i -D refurbish ``` -------------------------------- ### Install rEFui and refurbish dependencies with pnpm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Installs the 'refui' library and 'refurbish' (for HMR) using pnpm. These are essential for running rEFui applications with Vite. ```bash pnpm add refui pnpm add -D refurbish ``` -------------------------------- ### Install rEFui and refurbish dependencies with yarn Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Installs the 'refui' library and 'refurbish' (for HMR) using yarn. These are essential for running rEFui applications with Vite. ```bash yarn add refui yarn add -D refurbish ``` -------------------------------- ### esbuild JSX Setup - Classic Pragma (Shell) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/faq.mdx Command-line example for setting up esbuild with the classic JSX pragma. This is useful for per-file renderer swapping or Reflow classic patterns. ```shell esbuild src/main.jsx --bundle --outfile=dist/bundle.js --jsx-factory=R.c --jsx-fragment=R.f ``` -------------------------------- ### Run Vite development server with npm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to start the Vite development server using npm. This command compiles the project and serves it locally for development. ```bash npm run dev ``` -------------------------------- ### Run Vite development server with yarn Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to start the Vite development server using yarn. This command compiles the project and serves it locally for development. ```bash yarn dev ``` -------------------------------- ### Run Vite development server with pnpm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to start the Vite development server using pnpm. This command compiles the project and serves it locally for development. ```bash pnpm dev ``` -------------------------------- ### esbuild JSX Setup - Automatic Runtime (Shell) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/faq.mdx Command-line example for setting up esbuild with the automatic JSX runtime. This is the default for most applications and pairs well with Reflow. ```shell esbuild src/main.jsx --bundle --outfile=dist/bundle.js --jsx=automatic --jsx-import-source=refui ``` -------------------------------- ### Basic rEFui root component with a counter (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md A simple 'App' component for rEFui that demonstrates state management using signals and event handling for a button click. ```jsx import { signal } from 'refui' export default function App() { const count = signal(0) return (

Hello, rEFui

) } ``` -------------------------------- ### Render 'Hello, World!' Component to HTML Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/html-renderer.mdx A complete example showing how to render a simple rEFui component to an HTML string using the HTML renderer. It includes defining a component with a signal and then serializing the rendered output. ```jsx import { createHTMLRenderer } from 'refui/html'; import { signal } from 'refui'; // 1. Create renderer const renderer = createHTMLRenderer(); // 2. Define a component that accepts a renderer (R) const App = () => { const name = signal('World'); return ( <>

Hello, {name}!

This is rendered on the server.

); } // 3. Render the component to a variable const rendered = renderer.createElement(App); // 4. Serialize the output to an HTML string const htmlString = renderer.serialize(rendered); console.log(htmlString); // Output:

Hello, World!

This is rendered on the server.

``` -------------------------------- ### Create and Render 'Hello, World!' Component (index.jsx) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Demonstrates the creation of a simple 'Hello, World!' component and its rendering to the DOM using rEFui. It involves creating a DOM renderer and calling the render method with the target element and the component. ```jsx import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; // 1. Create a DOM renderer instance const renderer = createDOMRenderer(defaults); // 2. Define your component const App = () => { return

Hello, World!

; }; // 3. Render the component to a DOM element renderer.render( document.getElementById('app'), App ); ``` -------------------------------- ### Scaffold Vite Project with bun Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to create a new Vite project using bun. This command scaffolds a basic Vite application, which can then be configured for rEFui. ```bash bunx create-vite my-refui-app --template vanilla ``` -------------------------------- ### Minimal HTML structure for rEFui app Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Basic HTML file structure for a rEFui application, including a root element for rendering and a script tag pointing to the main JSX entry file. ```html rEFui
``` -------------------------------- ### Render 'Hello, World!' Component (JSX) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/dom-renderer.mdx Demonstrates rendering a simple 'Hello, World!' component to the DOM using JSX and the rEFui DOM renderer. This example includes setting up the HTML structure and the JavaScript logic for rendering. It assumes JSX is configured using the Classic Transform. ```html
``` ```jsx import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; // 1. Create renderer const renderer = createDOMRenderer(defaults); // 2. Define a component that accepts a renderer (R) const App = () =>

Hello, World!

; // 3. Render the component to a DOM element renderer.render(document.getElementById('app'), App); ``` -------------------------------- ### Project Setup: Using Macros for Reusable DOM Behaviors Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Advises registering macros for repeated DOM behaviors and using them via `m:*` syntax. This avoids code duplication and centralizes complex DOM interactions. ```javascript m:* ``` -------------------------------- ### Project Setup: Renderer Creation at Entry Point Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Emphasizes the best practice of creating the rEFUI renderer only at the application's entry point, not within individual components, to maintain a single, stable rendering context. ```javascript createRenderer(...) ``` -------------------------------- ### Reflow Renderer Example: Platform-Specific Components Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This JSX example demonstrates creating platform-specific components using the Reflow renderer. It shows how to conditionally render UI elements based on the detected runtime platform (browser, nativescript, etc.) and interact with platform-specific APIs. ```jsx import { signal, useAction, read, watch, onDispose } from 'refui' // R for Reflow is auto injected by your bundler, or you can do it manually // import { R } from 'refui/reflow' // Or import directly from 'refui' // Or configure JSX automatic runtime for your bundler const platform = globalThis.RUNTIME_PLATFORM ?? 'browser' export const CounterDisplay = ({ count }) => { if (platform === 'browser') return () => {count} if (platform === 'nativescript') return () => {count} if (platform === 'cheesedom') return () => {count} if (platform === 'breadboard') { const display = new LED('max7219') watch(() => { display.setText(read(count).toString(10)) }) onDispose(() => { display.close() }) } return null } export const CounterBtn = ({ onIncrement }) => { let lastInc = 0 const debounced = () => { const now = Date.now() if (now - lastInc < 100) return lastInc = now onIncrement() } if (platform === 'browser') return () => if (platform === 'nativescript') return () => if (platform === 'cheesedom') return () => + if (platform === 'breadboard') { const gpio = GPIO.open('A1', 'input') gpio.on('edge_up', onIncrement) onDispose(() => { gpio.close() }) } return null } export const App = () => { const count = signal(0) const [whenIncrement, increment] = useAction() whenIncrement(() => { count.value += 1 }) return ( <> ) } ``` -------------------------------- ### Project Setup: Default Configuration Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Outlines the default project setup choices: JSX automatic runtime, JavaScript, and the latest version of `refui` from npm. This simplifies the initial project scaffolding. ```javascript npm install refui ``` -------------------------------- ### Install rEFui via npm Source: https://github.com/sudomaker/refui/blob/main/README.md This command installs the rEFui package using npm. It's the first step to start using the framework in your project. ```shell npm i refui ``` -------------------------------- ### Install refurbish for HMR Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This command installs the refurbish package as a development dependency, which provides hot module replacement capabilities for RefUI components. ```bash npm install -D refurbish ``` -------------------------------- ### Create HTML Renderer Instance Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/html-renderer.mdx Demonstrates the initial setup for creating an instance of the HTML renderer in rEFui. This renderer is used for server-side rendering (SSR) to generate static HTML strings. ```javascript import { createHTMLRenderer } from 'refui/html'; // Create the renderer const renderer = createHTMLRenderer(); ``` -------------------------------- ### Scaffold Vite Project with npm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to create a new Vite project using npm. This command scaffolds a basic Vite application, which can then be configured for rEFui. ```bash npm create vite@latest my-refui-app -- --template vanilla ``` -------------------------------- ### rEFui DOM renderer and root component rendering (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Entry point for a rEFui application using the DOM renderer. It sets up the renderer and renders the main 'App' component into the specified root element. ```jsx import { createDOMRenderer } from 'refui/dom' import { defaults } from 'refui/browser' import App from './App.jsx' const renderer = createDOMRenderer(defaults) const root = document.getElementById('app') renderer.render(root, App) ``` -------------------------------- ### Render a RefUI App with DOM Renderer Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This JavaScript example demonstrates how to render a RefUI application into the DOM. It imports the `createDOMRenderer` and `defaults` from 'refui', creates a renderer instance, and then calls the `render` method with the target DOM element and the root application component. ```javascript import { createDOMRenderer } from 'refui/dom' import { defaults } from 'refui/browser' import App from './App.jsx' // Your root component const R = createDOMRenderer(defaults) const root = document.getElementById('app') R.render(root, App) ``` -------------------------------- ### Conditional Rendering with If Component (rEFui) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Demonstrates conditional rendering using rEFui's `` component. It shows how to conditionally display content based on a signal's value and how to use the `$` helper for dynamic text. ```jsx import { signal, If, $ } from 'refui'; const LoginStatus = () => { const isLoggedIn = signal(false); return (
{() =>

Welcome back!

} {() =>

Please log in.

}
); }; ``` -------------------------------- ### Create Default Browser DOM Renderer Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/dom-renderer.mdx Initializes a DOM renderer with default browser configurations. This is the most common setup for web applications. It requires the 'refui/dom' and 'refui/browser' modules. ```javascript import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; // Create the renderer with browser defaults const renderer = createDOMRenderer(defaults); ``` -------------------------------- ### Scaffold Vite Project with yarn Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to create a new Vite project using yarn. This command scaffolds a basic Vite application, which can then be configured for rEFui. ```bash yarn create vite my-refui-app --template vanilla ``` -------------------------------- ### Scaffold Vite Project with pnpm Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Command to create a new Vite project using pnpm. This command scaffolds a basic Vite application, which can then be configured for rEFui. ```bash pnpm create vite my-refui-app --template vanilla ``` -------------------------------- ### Rendering Lists with For Component (rEFui) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Shows how to render lists of items efficiently using rEFui's `` component. It iterates over a signal containing an array of todos and renders each todo item as a list element. ```jsx import { signal, For } from 'refui'; const TodoList = () => { const todos = signal([ { text: 'Learn rEFui' }, { text: 'Build an app' }, { text: 'Profit' }, ]); return (
    {({ item }) =>
  • {item.text}
  • }
); }; ``` -------------------------------- ### Project Setup: Choosing Keyed Lists Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Recommends using the keyed `` component for rendering lists by default, unless performance profiling indicates a specific benefit from using unkeyed lists. ```javascript ``` -------------------------------- ### Browser DOM Renderer Setup Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Setup for creating a DOM renderer for browser applications using `refui/dom` and `refui/browser`. ```javascript import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; const renderer = createDOMRenderer(defaults); // ... use renderer ``` -------------------------------- ### Server-Side Rendering with Dynamic Data using Signals Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/html-renderer.mdx Illustrates how to perform server-side rendering with dynamic data using rEFui signals and computed values. This example renders a user profile component to an HTML string. ```jsx import { createHTMLRenderer } from 'refui/html'; import { signal, computed } from 'refui'; const renderer = createHTMLRenderer(); const UserProfile = ({ userId }) => { // These would typically be fetched from a database const user = signal({ name: 'John Doe', email: 'john@example.com', posts: 42 }); const displayName = computed(() => user.value.name || 'Anonymous User' ); return ( ); }; // Render to HTML const rendered = renderer.createElement(UserProfile, { userId: 123 }); const html = renderer.serialize(rendered); console.log(html); // Output: ``` -------------------------------- ### rEFui Context API Example Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Demonstrates how to use rEFui's `createContext` and `useContext` for dependency injection and sharing state within a component subtree. It shows creating a theme context and consuming it in a `Button` component. ```jsx import { signal, $, createContext, useContext } from 'refui' const Theme = createContext(signal('light'), 'Theme') const Button = () => { const theme = useContext(Theme) return } ``` -------------------------------- ### Build a Reactive Counter Component (index.jsx) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Illustrates building an interactive counter component using rEFui signals. It shows how to create a signal for state, update it on button clicks, and have the UI automatically re-render when the signal's value changes. ```jsx import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; import { signal } from 'refui'; // 1. Create renderer const renderer = createDOMRenderer(defaults); // 2. Define the Counter component const Counter = () => { // Create a reactive signal with an initial value of 0 const count = signal(0); // The component's UI will automatically update when `count` changes return (

Count: {count}

); }; // 3. Render the component renderer.render( document.getElementById('app'), Counter ); ``` -------------------------------- ### SSR/SSG HTML Renderer Setup Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Setup for creating an HTML renderer for Server-Side Rendering (SSR) or Static Site Generation (SSG) using `refui/html`. ```javascript import { createHTMLRenderer } from 'refui/html'; const renderer = createHTMLRenderer(); const html = renderer.serialize(); // ... use html ``` -------------------------------- ### Configure Vite for rEFui JSX automatic runtime (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md Configuration for Vite to enable JSX automatic runtime with 'refui' as the import source. Includes the optional 'refurbish' plugin for HMR. ```javascript import { defineConfig } from 'vite' import { refurbish } from 'refurbish/vite' export default defineConfig({ plugins: [refurbish()].filter(Boolean), esbuild: { jsx: 'automatic', jsxImportSource: 'refui', }, }) ``` -------------------------------- ### Boolean Logic Shorthands Example (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/faq.mdx Illustrates the use of signal helpers for common boolean patterns like inverse, and, or, choose, and select. These helpers return reactive signals, simplifying state management. ```javascript const enabled = signal(true); const disabled = enabled.inverse(); const status = isReady.choose('ready', 'pending') ``` -------------------------------- ### Counter Example with Signals, Computed, and Watch in JavaScript Source: https://github.com/sudomaker/refui/blob/main/docs/pages/concepts/signals.mdx A complete example demonstrating the integration of `signal`, `computed`, and `watch` in JavaScript to build a simple counter application that logs the current and doubled values. ```javascript import { signal, computed, watch } from 'refui/signal' const count = signal(0) const doubled = computed(() => count.value * 2) watch(() => { console.log(`Count: ${count.value}, Doubled: ${doubled.value}`) }) count.value = 5 // Logs: "Count: 5, Doubled: 10" ``` -------------------------------- ### rEFui DOM Renderer Setup Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Shows how to set up and use the rEFui DOM renderer for client-side rendering in a browser environment. It involves importing the renderer and calling its `render` method with the target element and the root component. ```jsx import { createDOMRenderer } from 'refui/dom' import { defaults } from 'refui/browser' createDOMRenderer(defaults).render(document.getElementById('app'), App) ``` -------------------------------- ### Project Setup: Localizing State with Signals Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Recommends localizing state within components using signals and utilizing `extract` or `derivedExtract` to minimize the scope and impact of state changes, promoting better performance and maintainability. ```javascript extract(...) ``` ```javascript derivedExtract(...) ``` -------------------------------- ### Configure Classic JSX Transform in RefUI Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/project-setup.md This snippet shows how to configure the transpiler for classic JSX transform by setting `jsxFactory` and `jsxFragment`. It also demonstrates injecting Reflow's R object for classic mode. ```javascript { // ... other transpiler options "jsxFactory": "R.c", "jsxFragment": "R.f" } ``` ```javascript import { R } from 'refui/reflow' ``` -------------------------------- ### Configure JSX with Vite (vite.config.js) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Sets up JSX for rEFui within a Vite project by configuring the esbuild options in vite.config.js. It enables automatic JSX runtime and specifies 'refui' as the import source. ```javascript // vite.config.js import { defineConfig } from 'vite'; export default defineConfig({ esbuild: { jsx: 'automatic', jsxImportSource: 'refui' }, }); ``` -------------------------------- ### Computed Signal Update Example (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/faq.mdx Demonstrates how to ensure a computed signal updates correctly by reading its dependencies upfront. This prevents issues where early returns might prevent signal tracking. The '$' shorthand is also mentioned. ```javascript const summary = computed(() => { const t = track.value // read first const meta = metadata.value // read first if (!t) return 'Ready' return `${t.name} – ${meta}` }) // `$` is a shorthand: const summary = $(() => { ... }) ``` -------------------------------- ### State Management with Signals in rEFUI Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Demonstrates the basic pattern for creating reactive state using `signal` in rEFUI. This is the foundation for most reactive data in the library. The `initial` value determines the starting state of the signal. ```javascript const x = signal(initial) ``` -------------------------------- ### Instantiate Base Component Class Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/core-api.mdx Provides an example of directly instantiating the base `Component` class. However, it's generally recommended to use `createComponent` instead for better abstraction and lifecycle management. ```jsx import { Component } from 'refui'; // Direct instantiation (not recommended) const instance = new Component(MyTemplate, props, ...children); ``` -------------------------------- ### Conditional and List Rendering in rEFui JSX Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/html-renderer.mdx Shows how to implement conditional rendering with the `If` component and list rendering with the `For` component within rEFui JSX. This example demonstrates rendering a blog post list. ```jsx import { For, If } from 'refui'; const BlogPost = ({ title, content, published }) => (

{title}

{() =>

{content}

} {() =>

This post is not yet published.

}
); const BlogIndex = () => { const posts = signal([ { id: 1, title: 'First Post', content: 'Hello world!', published: true }, { id: 2, title: 'Draft Post', content: 'Work in progress...', published: false } ]); return (

My Blog

{({ item }) => ( )}
); }; ``` -------------------------------- ### Classic JSX Transform Configuration (Vite/esbuild) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Configuration example for classic JSX transform using `R.c` as the factory and `R.f` as the fragment in Vite or esbuild. ```javascript { // ... jsxFactory: 'R.c', jsxFragment: 'R.f' // ... } ``` -------------------------------- ### Handling Asynchronous Operations with Async Component (rEFui) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Demonstrates simplifying asynchronous operations with rEFui's `` component. It handles the pending, resolved, and error states of a promise, providing fallbacks and displaying results or errors accordingly. ```jsx import { Async } from 'refui'; // A mock API call that resolves after 1 second const fetchUser = () => new Promise((resolve) => { setTimeout(() => resolve({ name: 'John Doe' }), 1000); }); const UserProfile = () => { const userPromise = fetchUser(); return (

Loading user...

} catch={({ error }) =>

Error: {error.message}

} > {({ result: user }) =>

Welcome, {user.name}!

}
); }; ``` -------------------------------- ### rEFui Signals and Reactive JSX Example Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Demonstrates the basic usage of signals for state management and reactive rendering in rEFui. It shows how to create a signal, update it via an event handler, and display its value reactively in JSX. ```jsx import { signal, $ } from 'refui' const Counter = () => { const count = signal(0) return ( ) } ``` -------------------------------- ### Automatic JSX Runtime Configuration (Vite/esbuild) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Configuration example for automatic JSX runtime with `refui` as the import source in Vite or esbuild. ```javascript { // ... jsx: 'automatic', jsxImportSource: 'refui' // ... } ``` -------------------------------- ### Configure JSX with Bun (tsconfig.json) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Configures JSX for rEFui using the 'react-jsx' compiler option and specifies 'refui' as the import source in tsconfig.json. This is essential for using JSX syntax with rEFui. ```json { "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "refui" } } ``` -------------------------------- ### Configure JSX with Babel (.babelrc.json) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Configures the Babel preset for React to support rEFui's JSX. It enables the automatic runtime and sets 'refui' as the import source, ensuring proper JSX transformation. ```json { "presets": [ [ "@babel/preset-react", { "runtime": "automatic", "importSource": "refui" } ] ] } ``` -------------------------------- ### Component with Reactive Props (JSX) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/dom-renderer.mdx Illustrates how components can receive and use reactive props. This example shows a 'Greeting' component that takes 'name' and 'count' props, which are signals. The parent component updates these signals, and the 'Greeting' component re-renders accordingly. ```jsx import { signal, read } from 'refui'; const Greeting = ({ name, count }) => { return (

Hello, {name}!

You have {count} messages

); }; const App = () => { const userName = signal('John'); const messageCount = signal(5); return (
); }; ``` -------------------------------- ### Configure esbuild for Reflow Renderer Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This esbuild configuration demonstrates how to set up the JSX factory, fragment, and inject the Reflow R import for renderer-agnostic JSX. This is an alternative to Vite for bundling. ```javascript import { build } from 'esbuild' await build({ entryPoints: ['src/main.jsx'], outfile: 'dist/bundle.js', bundle: true, jsxFactory: 'R.c', jsxFragment: 'R.f', jsxInject: `import { R } from 'refui/reflow'`, }) ``` -------------------------------- ### Configure Vite for RefUI Automatic JSX Runtime Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This Vite configuration example demonstrates how to enable the automatic JSX runtime for RefUI. It sets the `jsx` option to 'automatic' and `jsxImportSource` to 'refui' within the `esbuild` configuration, ensuring Vite uses RefUI's JSX transformation. ```javascript import { defineConfig } from 'vite' export default defineConfig({ esbuild: { jsx: 'automatic', jsxImportSource: 'refui', // This tells Vite/esbuild where to find the runtime }, }) ``` -------------------------------- ### Configure esbuild for RefUI Automatic JSX Runtime (JS API) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This JavaScript API example configures esbuild to use RefUI's automatic JSX runtime. Similar to the CLI version, it sets `jsx: 'automatic'` and `jsxImportSource: 'refui'` in the build options. ```javascript import { build } from 'esbuild' await build({ entryPoints: ['src/main.jsx'], outfile: 'dist/bundle.js', bundle: true, jsx: 'automatic', jsxImportSource: 'refui', }) ``` -------------------------------- ### Configure JSX Classic Transform in Babel Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx Configures Babel to use the classic JSX runtime with rEFui's pragma. This setup ensures that Babel correctly transforms JSX syntax using 'R.c' for elements and 'R.f' for fragments. ```json { "presets": [ [ "@babel/preset-react", { "runtime": "classic", "pragma": "R.c", "pragmaFrag": "R.f" } ] ] } ``` -------------------------------- ### rEFui Control Flow Components Example (If and For) Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Illustrates the use of rEFui's control flow components, `If` and `For`, for conditional rendering and list rendering. It shows how to conditionally display content or a list of items, including handling empty states. ```jsx import { signal, $, If, For } from 'refui' const App = () => { const items = signal([{ id: 1, name: 'A' }]) return ( items.value.length)}> {() => {({ item }) =>
{item.name}
}
} {() =>
Empty
}
) } ``` -------------------------------- ### Classic JSX Transform File Pragma Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Example of using a file pragma for classic JSX transform with `R.c`. ```javascript /** @jsx R.c */ // ... component code ``` -------------------------------- ### Conditional Rendering with rEFui If Component Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Example of using the rEFui `If` component for conditional rendering, including handling empty states for lists. ```jsx items.value.length)}> {({ item }) => } ``` -------------------------------- ### Lifecycle Effects: watch, useEffect, onDispose in rEFui Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/dos-and-donts.md Use `watch(fn)` for reactive computations within a component scope for automatic disposal. Employ `useEffect(setup)` for setup and cleanup logic like DOM listeners or intervals, returning the cleanup function. Utilize `onDispose(cleanup)` for teardown-only cleanup within the current scope. Avoid global listeners without cleanup and creating effects outside component scopes unless process-lifetime behavior is intended. rEFui automatically tracks signal dependencies, eliminating the need for dependency arrays. ```javascript import { signal, computed, watch, useEffect, onDispose, nextTick } from "@preact/signals-core"; const counter = signal(0); // Do: Use watch for reactive computations within scope function MyComponent() { watch(() => { console.log("Counter changed:", counter.value); // This effect disposes when MyComponent unmounts }); // Do: Use useEffect for setup and cleanup useEffect(() => { const timerId = setInterval(() => { counter.value++; }, 1000); // Return cleanup function return () => clearInterval(timerId); }); // Do: Use onDispose for teardown-only cleanup onDispose(() => { console.log("MyComponent is disposing"); // Perform cleanup actions here }); return
Counter: {counter}
; } // Don't: Add global listeners without cleanup // window.addEventListener('resize', handleResize); // Missing cleanup // Don't: Create effects outside a component scope (unless intended) // watch(() => console.log('Global effect')); // Runs for the lifetime of the process // Don't: Use dependency arrays (they are not used in rEFui) // useEffect(() => { ... }, [dependency]); // Incorrect usage in rEFui ``` -------------------------------- ### Reflow Logic-Only Module Usage Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Example of using `refui/reflow` for logic-only modules, often injected via `jsxInject` in classic mode. ```javascript // In classic mode config: jsxInject: "import { R } from 'refui/reflow'" // ... component code using R ``` -------------------------------- ### Reactive Effects and Cleanup in rEFUI Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Illustrates how to perform side effects in response to state changes using `watch` or manage setup and cleanup logic with `useEffect` and `onDispose`. `watch` is for reactive computations, while `useEffect` and `onDispose` handle lifecycle-bound operations. ```javascript watch(fn) ``` ```javascript useEffect(setup) ``` ```javascript onDispose(cleanup) ``` -------------------------------- ### Creating a DOM Renderer with a Custom Document Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/custom-renderer.mdx This example shows how to utilize `createDOMRenderer` by providing a custom `doc` object that mimics the browser's Document API. This is useful when the target platform has a DOM-like interface but requires specific implementations for certain methods. ```javascript import { createDOMRenderer } from 'refui' // Assume 'customDoc' is an object implementing the necessary Document methods // like createElement, createTextNode, etc., for your specific platform. const customDoc = { // ... implementation of DOM API methods ... }; const renderer = createDOMRenderer({ doc: customDoc, rendererID: 'my-custom-renderer', namespaces: { 'svg': 'http://www.w3.org/2000/svg' }, tagNamespaceMap: { 'svg': 'svg', 'path': 'svg' }, tagAliases: { 'v': 'view' }, propAliases: { 'class': 'className', 'for': 'htmlFor' }, onDirective: (node, name, value) => { /* handle custom directives */ }, macros: { 'icon': (name) => ({ tag: 'span', props: { 'data-icon': name } }) } }); // Now you can use 'renderer' to render your RefUI application // renderer.render(rootElement, App); ``` -------------------------------- ### Initialize DOM Renderer with Browser Defaults Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/presets.mdx Initializes the DOM renderer for browser environments using the default presets provided by rEFui. This setup includes pre-defined tag namespaces and attributes suitable for web applications. ```javascript import { createDOMRenderer } from 'refui/dom' import { defaults } from 'refui/browser' export const renderer = createDOMRenderer(defaults) ``` -------------------------------- ### Configure Bun for refurbish HMR Plugin Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This TOML snippet shows how to configure Bun to use the refurbish HMR plugin. By adding `refurbish/bun` to the `plugins` array in the `[serve.static]` section of `bunfig.toml`, Bun will automatically enable HMR for RefUI components. ```toml [serve.static] plugins = ["refurbish/bun"] ``` -------------------------------- ### Configure JSX Classic Transform with esbuild JS API Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx Configures esbuild programmatically using its JavaScript API to bundle a project with the classic JSX transform. It sets 'R.c' as the JSX factory and 'R.f' as the JSX fragment factory. ```javascript import { build } from 'esbuild' await build({ entryPoints: ['src/main.jsx'], outfile: 'dist/bundle.js', bundle: true, jsxFactory: 'R.c', jsxFragment: 'R.f', }) ``` -------------------------------- ### Use Directives with DOM Renderer Source: https://github.com/sudomaker/refui/blob/main/skills/refui/references/jsx-and-renderers.md This example shows common directives used with the DOM renderer for handling events, classes, styles, attributes, and properties. These directives enhance component interactivity and styling. ```javascript
``` -------------------------------- ### Configure Vite for refurbish HMR Plugin Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/jsx-setup.mdx This JavaScript configuration example integrates the refurbish HMR plugin into a Vite project. By importing `refurbish` from 'refurbish/vite' and adding it to the `plugins` array in `vite.config.js`, Vite will enable hot module replacement for RefUI components. ```javascript import { defineConfig } from 'vite'; import { refurbish } from 'refurbish/vite'; export default defineConfig({ plugins: [refurbish()] }); ``` -------------------------------- ### Memoization with useMemo Wrapper in RefUI Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/components/basic.mdx Illustrates the use of the `useMemo` wrapper to create reusable memoized components. The `useMemo` helper prepares a function that, when invoked inside a component, captures the correct reactive context for memoization. This is useful for preparing content that might be rendered in multiple places. ```jsx import { useMemo, signal, If, $ } from 'refui' const renderDetails = useMemo((R) =>

Detailed view created once

) const renderSummary = useMemo((R) =>

Summary created once

) const ToggleMessage = () => { const isOpen = signal(false) return (
{renderDetails()} {renderSummary()}
) } ``` -------------------------------- ### Incorrect Reactive Expression in JSX (rEFui) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Demonstrates a common mistake where dynamic expressions are placed directly in JSX, leading to non-reactive behavior. This expression is evaluated only once during initial render and will not update when the `count` signal changes. Requires the `signal` function from 'refui'. ```jsx import { signal } from 'refui'; const IncorrectCounter = () => { const count = signal(0); return (

Count is: {count.value}

); }; ``` -------------------------------- ### Create Component Instance Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/core-api.mdx Illustrates how to create an instance of a component using the `createComponent` function. It takes the component template and optional props, returning a component instance that can be used with the `Render` component. ```jsx import { createComponent } from 'refui'; const MyComponent = ({ name }) =>
Hello, {name}!
; // Create component instance const instance = createComponent(MyComponent, { name: 'World' }); // Can be used with Render component const App = () => ; ``` -------------------------------- ### Create Reactive Counter Component with Signals (JSX) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/dom-renderer.mdx Example of creating an interactive counter component using rEFui's reactive signals. The component manages its own state ('count') and updates the UI when buttons are clicked. It demonstrates how signals automatically trigger re-renders. ```jsx import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; import { signal } from 'refui'; const renderer = createDOMRenderer(defaults); const Counter = () => { // Create a reactive signal const count = signal(0); return (

Count: {count}

); }; renderer.render(document.getElementById('app'), Counter); ``` -------------------------------- ### Correct Reactive Expression in JSX using Computed Signals (rEFui) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/getting-started.mdx Shows the correct way to handle reactive expressions in rEFui JSX by wrapping them in a computed signal `$(...)`. This ensures that the expression updates automatically when the underlying signal (`count`) changes. Requires `signal` and `$` (computed) from 'refui'. ```jsx import { signal, $ } from 'refui'; const CorrectCounter = () => { const count = signal(0); const message = $(() => `Count is: ${count.value}`); return (

{message}

); }; ``` -------------------------------- ### Event Listener with Multiple Options (JSX) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/dom-renderer.mdx Demonstrates attaching an event listener with multiple options, such as 'capture' and 'passive', using the 'on-capture-passive' directive in JSX. This allows for fine-grained control over event propagation and behavior. The example shows a click event listener that captures the event in the capturing phase and is passive. ```jsx
alert('Clicked!')}>
``` -------------------------------- ### Create Renderer Instance Once (JavaScript) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/best-practices.mdx Demonstrates the correct way to create a single DOM renderer instance at the application's entry point. This avoids unnecessary renderer instances within components, improving performance and resource management. ```jsx // ✅ Good: Create renderer once in main.js import { createDOMRenderer } from 'refui/dom'; import { defaults } from 'refui/browser'; // Single renderer instance export const renderer = createDOMRenderer(defaults); // Use throughout your app renderer.render(document.getElementById('app'), App); ``` ```jsx // ❌ Avoid: Creating renderers in components const MyComponent = () => { // Don't do this - creates unnecessary renderer instances const renderer = createDOMRenderer(defaults); return
Hello
; }; ``` -------------------------------- ### Basic Component Creation (JSX) Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/core-api.mdx Demonstrates the basic syntax for creating a component using JSX with the automatic runtime. Components are defined as functions returning JSX. ```jsx const Comp = (props) =>
``` -------------------------------- ### Implement Custom DOM Event Listener with rEFui Macro Source: https://github.com/sudomaker/refui/blob/main/docs/pages/guides/llm-guidelines.mdx Shows how to replace manual DOM event listeners with rEFui's macro system for better integration with the component lifecycle. This example creates a `clickOutside` macro that cleans up the event listener using `onDispose`. ```javascript renderer.useMacro({ name: 'clickOutside', handler(node, value) { if (!value) return const listener = (event) => { if (!node.contains(event.target)) value() } document.addEventListener('click', listener) onDispose(() => document.removeEventListener('click', listener)) } }) // Usage in JSX: //
setOpen(false)} /> ``` -------------------------------- ### Get DOM Element or Component Reference with `$ref` Prop Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/core-api.mdx The `$ref` prop provides a way to get a reference to a rendered DOM element or custom component instance. It supports assigning the reference to a signal's `.value` or passing it to a callback function for direct manipulation. ```jsx import { signal } from 'refui'; const MyComponent = () => { // Using signal for ref const buttonRef = signal(); // Using function for ref const handleInputRef = (inputElement) => { inputElement.focus(); }; return (
); }; ``` -------------------------------- ### Create and Manage Signals in rEFui (JavaScript) Source: https://context7.com/sudomaker/refui/llms.txt Demonstrates how to create basic and derived signals using the `signal` function in rEFui. It covers reading, writing, and utilizing signal methods like `peek`, `poke`, `trigger`, and `touch`. Also shows chaining operations for boolean logic and conditional selection with `select` and nullish coalescing with `nullishThen`. ```javascript import { signal, watch, nextTick } from 'refui' // Basic signal const count = signal(0) // Read value console.log(count.value) // 0 // Write value count.value = 5 // Derived signal with compute function const doubled = signal(count, (val) => val * 2) console.log(doubled.value) // 10 // Signal methods count.peek() // Read without tracking (returns 5) count.poke(10) // Write without triggering effects count.trigger() // Manually trigger effects count.touch() // Register dependency without reading // Chain operations for boolean logic const isPositive = count.gt(0) // count > 0 const isEven = signal(count, v => v % 2 === 0) const showMessage = isPositive.and(isEven) // Both true // Conditional selection const status = signal('loading') const message = status.select({ loading: 'Please wait...', success: 'Done!', error: 'Something went wrong' }) // Nullish coalescing const username = signal(null) const displayName = username.nullishThen('Guest') ``` -------------------------------- ### Render Component Instance Source: https://github.com/sudomaker/refui/blob/main/docs/pages/reference/core-api.mdx Demonstrates how to render a component instance using the `render` function and a specific renderer, such as the DOM renderer. It takes the component instance and a renderer as input and returns the rendered node or element. ```jsx import { createComponent, render } from 'refui'; import { createDOMRenderer } from 'refui/dom'; const renderer = createDOMRenderer(); const instance = createComponent(MyComponent, { name: 'World' }); const node = render(instance, renderer); ``` -------------------------------- ### Create and Update Signals in JavaScript Source: https://github.com/sudomaker/refui/blob/main/docs/pages/concepts/signals.mdx Demonstrates how to create a reactive signal with an initial value and how to retrieve and update its current value in JavaScript using the 'refui/signal' library. ```javascript import { signal } from 'refui/signal' // Create a signal with an initial value const count = signal(0) // Get the current value console.log(count.value) // 0 // Update the value count.value = 5 console.log(count.value) // 5 ``` -------------------------------- ### Registering and Using Macros in rEFUI Source: https://github.com/sudomaker/refui/blob/main/skills/refui/SKILL.md Describes how to register custom DOM behaviors as macros and apply them using the `m:` prefix. This promotes code reuse for repeated DOM manipulation patterns. ```javascript m:name={value} ```